Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewWillAppear not called in UITableViewController?

I have a couple of UITableViewController classes and I just noticed that these methods aren't being called:

-(void)viewWillAppear:(BOOL)animated;
-(void)viewDidAppear:(BOOL)animated;

I read in http://discussions.apple.com/thread.jspa?threadID=1529769&tstart=0 that I would have to call those methods myself when pushing view controllers, but that's strange, since it works for anything but UITableViewController.

Also makes it a bit of an issue when I need to have a UITableViewCell deselected in the UIViewController that pushed the UITableViewController.

like image 751
runmad Avatar asked Mar 10 '10 15:03

runmad


People also ask

Why ViewWillAppear is not called?

There's always a catch With the new modal presentation, however, ViewWillAppear won't get called on the presenting view controller when the presented view controller is dismissed, because technically its view never left the view hierarchy.

What is ViewWillAppear in Swift?

Notifies the view controller that its view is about to be added to a view hierarchy.

What triggers ViewWillAppear?

The method viewWillAppear: is triggered in response to a change in the state of the application, indicating that the view controller is becoming “active.”

What is the difference between viewDidLoad and viewDidAppear?

The difference between viewDidAppear and viewDidLoad is that viewDidAppear is called every time you land on the screen while viewDidLoad is only called once which is when the app loads.


1 Answers

I can't find it in the documentation, but I think this might be because you are using a UINavigationController.

How about setting the UINavigationController's delegate property and then implementing UINavigationControllerDelegate? It provides two optional methods:

– navigationController:willShowViewController:animated: 
– navigationController:didShowViewController:animated: 

For example, navigationController:willShowViewController:animated: might look something like this:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  if ([viewController isKindOfClass:[UITableViewController class]]) {
    [viewController viewWillAppear:animated];
  }
}

Anyway, this will get you the behavior you want without having to hack calls to viewWillAppear: all over your project.

like image 53
Rob Jones Avatar answered Oct 05 '22 10:10

Rob Jones