iphone Development Solution Viewwillappear failure

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.