Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does viewDidLoad wait before updating the UI?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>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 <em>at all</em> for two seconds, and finally when it becomes visible its label reads, "Second Text."</p> <p>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.</p> <p>Cheers.</p> <p><strong>UPDATE 1</strong>: Here's the viewDidLoad method:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; label.text = @"First Label"; sleep(2); label.text = @"Second Label"; } </code></pre> <p><strong>UPDATE 2</strong>: I made a silly mistake here, so please ignore this update.</p> <p><strong>UPDATE 3</strong>: I have now added the following to my viewDidAppear method:</p> <pre><code>- (void)viewDidAppear: (BOOL)animated { [super viewDidAppear: animated]; label.text = @"First Label"; sleep(2); label.text = @"Second Label"; } </code></pre> <p>Unfortunately I'm having exactly the same problem.</p> <p><strong>UPDATE 4</strong>: 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!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload