I'm having a problem with my navigation controller. If I add a view controller to the stack:
- (void) tui_ToggleListStudy:(id)sender
{
listVC = [[ListViewController alloc] init];
[self.navigationController pushViewController:listVC animated:NO];
[listVC release];
}
I have NSLog messages for the view controller beneath, for both viewWillDisappear:
and viewDidDisappear
- but only viewWillDisappear:
is getting called.
Not only that, but the view controller doesn't receive any other delegate messages either: No viewDidUnload
, or开发者_如何学编程 dealloc
...
Is there anything I can do about this?
I'm stumped! Any thoughts?
Thanks!
I know the answer if you made the same typo in your code that you made in your question: the method signature is viewDidDisappear:
(with the animated
argument), not viewDidDisappear
.
Not only that, but the view controller doesn't receive any other delegate messages either: No viewDidUnload, or dealloc...
A view controller will not be deallocated when you push another controller onto the stack. And viewDidUnload
won't be called unless you run out of memory.
Assuming your navigation controller is contained in some kind of top view controller, you must also forward the relevant messages from that top view controller to the nav controller:
-(void)viewWillAppear:(BOOL)animated
{
[navController viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated
{
[navController viewDidAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
[navController viewWillDisappear:animated];
}
-(void)viewDidDisappear:(BOOL)animated
{
[navController viewDidDisappear:animated];
}
You must call super at implementation of viewWillDisappear.
The designated initializer for UIViewController is -initWithNibName:bundle:
. Are you sure your view controller is finding its nib and finds its connected view? I'll bet if you set a breakpoint after init'ing your ListViewController, you'll find its -view returns nil.
精彩评论