UIViewController: viewWillAppear is called, viewDidAppear not

Sven Tiffe picture Sven Tiffe · Dec 3, 2010 · Viewed 9.6k times · Source

In a UIViewController subclass, I have the following methods:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // do something
    myTextField.text = @"Default";
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    // do something
    [myTextField selectAll:self];
    [myTextField becomeFirstResponder];
}

- (void)viewDidLoad {
    [super viewDidLoad];    
    // do something
    myTextField.delegate = self;
}

The NIB has been created using Interface Builder. The corresponding view controller object is pushed by the navigation controller through pushViewController.

The inteded behavior is to show a default text entry in a text field, to select the entire text and to set the text field as first responder. [Edit: I've noticed that selecting all and making first responder makes no sense as the selection would dissapear; still, I wonder why the methods behave as described next.]

However, while methods viewDidLoad and viewWillAppear are called, the method viewDidAppear is not called. Can anybody tell me why? Most questions I found on the web and here deal with both viewWillAppear/viewDidAppear are not working; I also understood that in subviews or programmatically created views these methods are not evoked; but this does not apply in case and also I wonder why one of these "lifecycle" methods is evoked and the other not.

Any idea? Thanks!

Answer

Andrew Soltan picture Andrew Soltan · Apr 20, 2014

I had this issue happen to me: viewWillAppear was being called but viewDidAppear was not!

I finally figured out that this was because I had a tabBarController where I overloaded it's own viewDidAppear and forgot the [super viewDidAppear:animated];

It threw off every VC in every tab! adding that line back in fixed it for my other VC's.

Hope this helps someone!