Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:42:05+00:00 2026-05-13T16:42:05+00:00

I’m just trying to get my head around the Objective-C event model on iPhone,

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:42:05+00:00Added an answer on May 13, 2026 at 4:42 pm

    Put your code that modifies the view in viewDidAppear:.

    The view is not yet visible when viewDidLoad and viewWillAppear: are called.

    UPDATE
    Just to be clear, I agree with the others that the correct way to do this is with a delayed method call or timer.

    UPDATE 2
    Here is the code that I am suggesting:

    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        NSLog(@"View will appear!");
    }
    
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
    
        NSLog(@"View did appear!");
    
        label.text = @"First Label";
        sleep(2);
        label.text = @"Second Label";
    }
    

    And the “correct” way:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        label.text = @"First Label";
    }
    
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        NSLog(@"View will appear!");
    }
    
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
    
        NSLog(@"View did appear!");
    
        [self performSelector:@selector(changeLabelText) withObject:nil afterDelay:2.0f];
    }
    
    - (void)changeLabelText {
        label.text = @"Second Label";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.