When using a UINavigationController the viewWillAppear or viewDidAppear methods of my controller are not called

后端 未结 6 1832
眼角桃花
眼角桃花 2020-12-30 06:21

Here is the pitch.

  • I have a UIViewController subclass which does something in its viewWillAppear and viewDidAppear methods.
  • I want to nest this view c
6条回答
  •  旧巷少年郎
    2020-12-30 07:12

    It is 2015 now and you probably don't need to use the UINavigationControllerDelegate methods as in the accepted answer. Just check carefully your code if you have any typo or copy/paste error.

    I ran into an issue lately that viewDidAppear is no longer called after some copy/paste. After reading @Yar's answer, I did a search on viewDidAppear in my code and found that [super viewDidAppear:animated]; was mistakenly called in viewWillAppear:

    -(void)viewWillAppear:(BOOL)animated
    {
       [super viewDidAppear:animated];
       //...      ^^^ 
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        // this is never called :(
    }
    

    Just share this finding here in case people run into same issue.

提交回复
热议问题