Я создал свой ViewController из UIViewController, где добавляю UILabel as;
@property (nonatomic, retain) UILabel * progressLabel;
Я инициализирую эту метку в 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? Однако в консоли отладчика я вижу следующий текст:
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" в метке прогресса?