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];
}发布于 2010-01-13 07:19:30
您可能需要尝试在每次图像加载完成后在主线程上调用myScrollView setNeedsDisplay。
发布于 2010-01-13 06:31:45
这种NSObject方法通常是有用的:
[someObject performSelectorOnMainThread:@selector(updateUI:) withObject:anotherObject waitUntilDone:YES /* or NO */];https://stackoverflow.com/questions/2054868
复制相似问题