Why isn't viewWillDisappear or viewDidAppear being called?

前端 未结 4 697
醉话见心
醉话见心 2020-12-31 21:59

I have a UINavigationController with a UITableView as my main menu. User clicks on a cell and a new view is pushed on the stack. In one case I push

相关标签:
4条回答
  • 2020-12-31 22:08

    i noticed the same issue in iOS7. When i'm using both tab bar (2 buttons A, B) and navigation controller.

    A has two views. One with tableview and second displays data according to the selection from the table view.

    B has is the only view.

    Button which is refer to another separate view D, placed in both tab bar views (A & B) and in both views of A.

    Problem arises when i click the button from tab item B, viewWillAppear and viewDidLoad not called.

    So i solved this issue by presentModalViewController:animated: and to come back i used dismissModalViewControllerAnimated:, just when i go to view D from tab item B.

    0 讨论(0)
  • 2020-12-31 22:19

    Although you solved your problem, in case someone comes along in the future another problem could have been that you forgot the animated: argument to either method - that is to say, the format of the method needs to look like:

    - (void) viewWillAppear:(BOOL)animated
    
    0 讨论(0)
  • 2020-12-31 22:22

    I have noticed behavior where if a parent controller (like UINavigationController or UITabBarController) never get's viewWill/DidAppear called on it, it won't call it on the child controllers either. So make sure that in the code where you create the parent controller, you call viewWillAppear, show it, then call viewDidAppear. Then it should make those calls on it's child controllers as is appropriate.

    Double check the parent controller is having those methods called, and call them yourself if they are not.

    0 讨论(0)
  • 2020-12-31 22:31

    Yes Its true

    you can do this by first write this code in

    - (void)viewDidLoad {
        self.navigationController.delegate = self;  
    }
    

    And then write the code which you want to write in viewWillAppear

    - (void)navigationController:(UINavigationController  *)navigationController didShowViewController:(UIViewController  *)viewController animated:(BOOL)animated {
    
        if ([viewController isKindOfClass:[self class]]) {
            //write your code here
        } 
    }
    
    0 讨论(0)
提交回复
热议问题