1.我的mainView是一个UIScrollView。我必须将 9 个图像作为图块加载到它上面。
2.我将该函数作为不同的线程调用以获取 9 个图像并将其加载到接口(主线程)中。通过这样做,界面保持响应。
3.但问题即使在加载图像时,它们也不会显示在 UIScrollView 中,直到整个线程完成。但是如果我在界面上做一些动作,我可以看到它们中的每一个都被加载和显示。
- 意味着在将每个图像加载到其中之后,我必须从后台线程更新接口(主线程)。
我该怎么做?我已经给出了用于将图像加载到 UIScrollView 的代码,我使用不同的线程调用它。
- (void)setUpDisplay:(NSArray *)array
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
myScrollView.userInteractionEnabled = YES;
myScrollView.multipleTouchEnabled = YES;
int x=0,y=0;
CGRect frame;
for (i = 0; i < 3; i++)
{
if(j == 3)
{
x=x+256;
y = y-768;
}
for (j = 0; j < 3; j++) {
imageView = [[UIImageView alloc] initWithImage:[self getCachedImage:[NSString stringWithFormat:@"url to fetch images"]]];
frame = [imageView frame];
frame.origin.x = x;
frame.origin.y = y;
[imageView setFrame:frame];
imageView.userInteractionEnabled = YES;
imageView.multipleTouchEnabled = YES;
[myScrollView addSubview:imageView];
y = y+256;
[imageView release];
imageView=nil;
}
}
[pool release];
}