I have a UILabel that I would like to update. It has been added to the class by ctrl-cicking and adding through the XIB file. Im trying to update the label text after waiting for a short delay. As of now, there is nothing else going on except for the code below. Howver when I run this, the simulator blanks out for a moment and takes me straight to the last updated text. It doesnt show me the 100 just the 200.
How do I get the label to update like I want it to. Ultimately Im trying to have a timer of sorts decrement inside the label.
Label linked from the XIB to header file:
@property (strong, nonatomic) IBOutlet UILabel *timeRemainingLabel;
In Implmentation:
- (void)viewDidLoad
{
[super viewDidLoad];
self.timeRemainingLabel.text = @"100";
sleep(1);
self.timeRemainingLabel.text = @"200";
}
-
It has been synthesized.
-
XCode 4.3.2, Mac OSX 10.7.3, iOS Simulator 5.1 (running iPad), iOS 5
The problem with your implementation is that the execution sequence does not leave the method while in the
sleep. This is the problem, because the UI subsystem never gets a chance to update the label to the"100"value before it gets a command to set it to"200".To do this correctly, first you need to create a timer in your init method, like this:
Then you need to write the code for your
updateLabelmethod: