Hello fellows. I'm just trying to get my head around the Objective-C event model on iPhone, and by the looks of things I have fundamentally misunderstood something here.
For the purpose of experimentation, in a view controller's -viewDidLoad method, I am setting a UILabel's text, then sleeping for two seconds, and then changing the label's text again.
My expectations are as follows: the label will first read, "First Text", then two seconds later it will be updated to read, "Second Text." Of course, this isn't quite how it happens. Instead, the view isn't visible at all for two seconds, and finally when it becomes visible its label reads, "Second Text."
Could somebody please explain to me what is going on? I'm interested to find out how you guys would achieve what I'm going for here.
Cheers.
UPDATE 1: Here's the viewDidLoad method:
- (void)viewDidLoad {
[super viewDidLoad];
label.text = @"First Label";
sleep(2);
label.text = @"Second Label";
}
UPDATE 2: I made a silly mistake here, so please ignore this update.
UPDATE 3: I have now added the following to my viewDidAppear method:
- (void)viewDidAppear: (BOOL)animated {
[super viewDidAppear: animated];
label.text = @"First Label";
sleep(2);
label.text = @"Second Label";
}
Unfortunately I'm having exactly the same problem.
UPDATE 4: Following gerry3 and Felix's suggestions, I have now implemented a performSelector, and boom! Works a treat!! I'm going to have to give it to gerry3 though as he certainly put the most amount of effort into helping me out. Thanks for all your contributions!