我從UIViewController創建了我的ViewController,其中添加了UILabel as; @property(nonatomic,retain)UILabel * progressLabel;無法更新UILabel中的文本
我初始化的loadView
- (void)loadView {
// Set main view to View Controller
UIView* localView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] ];
self.view = localView;
[localView release];
// Set progress label
self.progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 420, 320, 20) ];
[self.progressLabel setFont:[UIFont fontWithName:@"Georgia" size:12]];
[self.progressLabel setTextColor:[UIColor whiteColor]];
[self.progressLabel setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:self.progressLabel];
}
這個標籤,我必須更新標籤的文本
-(void) doSomethig {
for(int i = 0; i < 10; i++) {
NSString* str = [NSString stringWithFormat:@"%d", i];
[self.progressLabel setText:str];
[self.progressLabel.superview setNeedsDisplay];
NSLog(@"%@", self.progressLabel.text);
sleep(1);
}
}
爲什麼這個代碼不更新progressLabel.text性能的方法?然而在debuger控制檯我看到下面的文本:
2010-02-26 14:21:55.707 iLabelUpdate[6272:207] 0
2010-02-26 14:21:56.708 iLabelUpdate[6272:207] 1
2010-02-26 14:21:57.708 iLabelUpdate[6272:207] 2
2010-02-26 14:21:58.709 iLabelUpdate[6272:207] 3
2010-02-26 14:21:59.709 iLabelUpdate[6272:207] 4
2010-02-26 14:22:00.710 iLabelUpdate[6272:207] 5
2010-02-26 14:22:01.710 iLabelUpdate[6272:207] 6
2010-02-26 14:22:02.711 iLabelUpdate[6272:207] 7
2010-02-26 14:22:03.711 iLabelUpdate[6272:207] 8
2010-02-26 14:22:04.711 iLabelUpdate[6272:207] 9
當循環結束時,我可以看到「9」正在進行標籤?