0

I need a tabbed application to switch from view controller 2 to view controller 1 (home view controller) and then immediately call a method on view controller 1, without any input from the user. Using viewDidLoad doesn't work, since (as far as I can tell) the home view controller stays loaded the whole time; making it visible doesn't load it again. I've been trying to use -(void)tabBarController: didSelectViewController: but it's not getting called either, I assume because it only works with user-initiated selections, not programmatic selections.

So what can I do?

1 Answer 1

2

You can use the method -(void) viewWillAppear to do this. Once the view is already loaded, you do whatever you want when it appear! Here it is:

- (void) viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   // You code here to update the view.
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm. I just tried this in both view controller 1 and view controller 2, but the methods I put in it aren't getting called. I'm sure I'm misunderstanding--would you mind being more explicit about how I do this? Sorry for not getting it.
I edited my answer above! Check it out and test it! You can also include something like NSLog("Method being called when viewcontroller 1/2 appear") to check if this method is being called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.