还挺新iPhone编程与线程查看未更新
- (void)viewDidLoad {
[super viewDidLoad];
[NSThread detachNewThreadSelector:@selector(changeMain) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(changeThread) toTarget:self withObject:nil];
}
- (void)changeMain{
NSAutoreleasePool* arp = [[NSAutoreleasePool alloc] init];
for (int i = 0; i < 1000000; i++) {
[mainValue setText:[NSString stringWithFormat:@"%d",i]];
[self.view setNeedsDisplay];
}
[arp release];
}
- (void)changeThread{
NSAutoreleasePool* arp = [[NSAutoreleasePool alloc] init];
for (int i = 0; i < 1000000; i++) {
[threadValue setText:[NSString stringWithFormat:@"%d",i]];
[self.view setNeedsDisplay];
}
[arp release];
}
mainValue和threadValue被实验都只是UILabels。我期望这个运行,并看到两个标签运行到999999,而是从一些低数字开始(当我假设屏幕初始刷新时,它是什么),暂停了一下,然后更新到999999。我在想屏幕只是不令人耳目一新。
这是正确的吗?我做错了吗?
工作就像一个魅力。谢谢! – ACBurk 2009-10-04 18:27:36