So I’ve got a UITabBarController as a view in my app, the first tab of which is a UINavigationController. I have a button inside this view that pushes another, custom view onto the stack:
myViewController *vc = [[myViewController alloc] init];
[self pushViewController:myOtherView animated:YES];
The class myViewController has things that are supposed to happen inside of both -viewDidLoad and -viewDidAppear:(BOOL)animated, but if I hit my button right after the UITabBarController view appears, neither of those methods seem to be called. And even stranger, when I hit “Back”, the view does not animate away, but rather the view underneath it in the stack just pops back into place.
However, if I go to another tab in the tab bar, then go back to the first tab, then hit my button again, my custom view controller animates in, -viewDidAppear:(BOOL)animated is called, and it animates out of view upon hitting “Back” like it should. Unfortunately, -viewDidLoad is never called.
I’m really trying to get away from using Interface Builder for everything; I want to create this view controller purely programatically, but these weird issues aren’t helping. Can anyone think of a reason for this bizarre behavior?
Edit: Even if I create my view controller via IB, this behavior still occurs. What’s the deal? Do I need to do something to the UITabBarController?
Edit #2: Here’s how I want my views to bet set up:
- UITabBarControler
- Tab 1: UINavigationController
- UIViewController to be pushed onto the stack
- UIViewController to be pushed onto the stack
- etc (possibly more UIViewControllers)
- UIViewController to be pushed onto the stack
- Tab 2: UIViewController
- Tab 3: UINavigation Controller
- UIViewController to be pushed onto the stack
- UIViewController to be pushed onto the stack
- UIViewController to be pushed onto the stack
- Tab 1: UINavigationController
You don’t say what kind of object contains the code you posted but, if it’s handling a button action, it’s probably a custom view controller that’s managed by your navigation controller. If that’s true, then you’d want
[self.navigationController pushViewController:myOtherView animated:YES];.(If
selfis some other kind of object orself.navigationControlleris nil, then you would need to add some more details about your current view controller structure.)