下面是一段代码,它在我应用主线程的单独线程中运行。如何在每个按钮获取缩略图后获取UI?现在它不会更新,直到整个方法结束。这些按钮已被添加到UIScrollView。如何在此线程中更新UI?
(LotsGridButton只是一些额外的属性一个UIButton。)
- (void)fetchThumbnails {
CCServer* server = [[CCServer alloc] init];
for (int i=0; i<[buttons count]; i++) {
LotsGridButton* button = [buttons objectAtIndex:i];
if (button.lot.thumbnail) continue;
// load the thumbnail image from the server
button.lot.thumbnail = [server imageWithPath:button.lot.thumbnailURL];
[button setImage:button.lot.thumbnail forState:UIControlStateNormal];
}
[server release];
}
甜蜜!它工作,一旦我做了一个包装方法(因为performSelector只需要一个参数和setImage:forState:需要2)。这是一个普通模式的实例,就像“在主线程中更改小部件,它会马上显示其变化”? – lawrence 2009-04-30 06:17:22