简体   繁体   English

viewWillAppear方法未调用iPhone SDK

[英]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. 从一个视图导航到另一个视图,当我弹出视图时,viewWillAppear方法未调用。

can you please let me know the reason. 你能告诉我原因吗?

When you load View the first time viewWillAppear method is called? 第一次加载View时,调用viewWillAppear方法吗? try to use 尝试使用

[[self navigationController] popViewControllerAnimated:TRUE]; [[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 步骤1.用于推送FirstViewController

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

Step 2. for pop in SecondViewController 步骤2.在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. 阅读UIViewController类参考的“ 实现容器视图控制器”部分

I've also met this situation. 我也遇到过这种情况。 In iOS 5, it's ok. 在iOS 5中,可以。 But when I test in iOS 4.3.1, viewWillAppear is not calling. 但是当我在iOS 4.3.1中进行测试时,viewWillAppear没有调用。

So you need call viewWillAppear manually 所以你需要手动调用viewWillAppear

You can try this 你可以试试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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