简体   繁体   中英

viewWillAppear method is not calling iPhone SDK

navigated from one view to another will and when i pop my view back viewWillAppear method is not calling.

can you please let me know the reason.

When you load View the first time viewWillAppear method is called? try to use

[[self navigationController] popViewControllerAnimated:TRUE];

to return back

If u are doing all well than ur application is crashed some where, use break point and check , even you can check and follow these steps......

step 1. for push in FirstViewController

SecondViewController *second = [[SecondViewController alloc]init]
[self.navigationController pushViewController:second animated:TRUE];

Step 2. for pop in SecondViewController

//check navigation controller exist in ur application stack

NSArray *arrView = [self.navigationController viewControllers];

NSLog(@"arrView %@",arrView);

for(int i = 0; i <[arrView count]-1, i++)
{
    if([arrView objectAtIndex:i] isKindOfClass:[FirstViewController class])
    {
        [self.navigationController popViewControllerAnimated:TRUE];
    }
} 

It's typical that these problems are caused by improper use of view controller containment. You need to look at your view controller hierarchy and research the following methods:

[UIViewController addChildViewController:];
[UIViewController removeFromParentViewController:];
[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]
[UIViewController willMoveToParentViewController:]
[UIViewController didMoveToParentViewController:]

Read the Implementing a Container View Controller section of the UIViewController Class Reference.

I've also met this situation. In iOS 5, it's ok. But when I test in iOS 4.3.1, viewWillAppear is not calling.

So you need call viewWillAppear manually

You can try this

[[self.navigationController.viewControllers objectAtIndex:0] viewWillAppear:YES];
[self.navigationController popViewControllerAnimated:YES];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM