views:

780

answers:

4

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.

A: 

These two methods are called by default to notify for the changes. UITableViewController is a subclass of UIViewController, so there will be the same behavior. You can see more in the View Controller Programming Guide

The viewWillAppear: and viewDidAppear: methods give subclasses a chance to perform any additional actions related to the appearance of the view.

How do you know that these methods are not called? Can you provide some more codes, or at least you test them with a NSLog() to see if there are some messages printed.

sfa
I set breakpoints and NSLogs and nothing happens.
Canada Dev
can you provide some more codes of the implementation of these two methods, so that I can see what happens...
sfa
Hard to in the comment field. Basically I have a UINavigationController, and in the navigationBar, I have a UISegmentedControl. Switching the segment, the user switches between two views (profile and orders). Clicking an order should push the view onto another view (inside the same UINavigationController) which has the order details. Basically, it's the same as the "Featured" section of the App Store app. You have 3 segments, each with their own UITableView that can push in a new view. I've had a lot of issues trying to make this.
Canada Dev
I have not clearly understood your situation, but you might want to use these methods of the UISegmentedControl to control the behavior of the segments – setEnabled:forSegmentAtIndex:– isEnabledForSegmentAtIndex:.
sfa
Well, maybe some input then: How would you approach setting up a UINavigationController, inside the navigationBar would be a UISegmentedController, which would have 3 segments, each containing a UITableView and preserve the ability to push, etc?
Canada Dev
A: 

Did anyone resolve this because the original post is correct - simply using UITableViewController and pushing the table view of that controller onto the navController does NOT trigger these methods despite the fact that it should. I have a series of UITableViewControllers and table views that are pushed and popped to display hierarchical data - nothing fancy, but the "viewWill/Did/Appear/Disappear" methods are never called. Only the viewDidLoad and viewDidUnload are called.

There must be a wiring problem in both our setups, but simply pushing a view into the navigationController should be all that is required (?) - hard to believe that this could have gone unnoticed as a fundamental bug this long.

?

Huygir
A: 

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.

Rob Jones
A: 

I'm seeing the same problem. I have a simple UIView from the IB and I do a addSubview with a class that extends UITableViewController.

I can see the view of the TableViewController without problems in my application, but the viewWillAppear function is never called in this situation.

David Carvalho
I have learned that those delegate methods are only called for a UIViewController class.
Canada Dev