Transferred from: http://linuxstuding.iteye.com/blog/1224399
Have you ever encountered a situation where viewwillappear has not been called?
The reason is the use of Uinavigationcontroller.
Add Uinavigationcontroller view as Subview to other Viewcontroller's view.
Or add the Uinavigationcontroller to the Uitabbarcontroller.
At this point, the Navigationcontroller stack inside the Viewcontroller will not receive-(void) Viewwillappear: (BOOL) animated, such as 4 methods of invocation.
Why?
Apple Docs State:
Warning:if The view belonging to a view controller was added to a view hierarchy directly, the view controller would not re Ceive this message. If you insert or add a view to the view hierarchy, and it have a view controller, you should send the associated view CONTR Oller this message directly. Failing to send the view controller this message would prevent any associated animation from being displayed.
But later to 4.0 of the document did not find such a text description, but still can not be called to this
Just add more complex documents, dizzy Dizzy look down.
Workaround Two kinds:
1, the Viewwillappear method is explicitly called in the viewwillappear of the controller on the upper level of the navigation controllers.
-(void)Viewwillappear:(BOOL)Animated
{
[Super Viewwillappear:Animated];[SUBNAVCNTLR viewwillappear:animated];< Span class= "PLN" >
}
- (void) viewwilldisappear:( Span class= "PLN" >bool) animated
{
[super viewwilldisappear:animated
[SUBNAVCNTLR viewwilldisappear:< Span class= "PLN" >animated;
}
/span>
2, set the navigation controller upper controllers to Uinavigationcontroller delegate
Nav.delegate = self;
@interface Rootviewcontroller:uiviewcontroller <UINavigationControllerDelegate> { Uinavigationcontroller *navcontroller;}
-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Willshowviewcontroller: ( Uiviewcontroller *) Viewcontroller animated: (BOOL) animated { [Viewcontroller viewwillappear:animated];} -(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Didshowviewcontroller: ( Uiviewcontroller *) Viewcontroller animated: (BOOL) animated { [Viewcontroller viewdidappear:animated];}
Make it work, I like the second one, but I prefer to stop doing things in viewwillappear.
iphone Development Solution Viewwillappear failure