viewDidAppear not getting called

后端 未结 8 968
醉酒成梦
醉酒成梦 2021-01-12 00:17

In my main UIViewController I am adding a homescreen view controller as subviews:

   UINavigationController *controller = [[UINavigationController alloc] ini         


        
相关标签:
8条回答
  • 2021-01-12 00:26

    When updating my code to 13.0, I lost my viewDidAppear calls.

    In Objective-c, my solution was to add the following override all to the parent master view controller.

    This allowed the ViewDidAppear call to get called once again...as it did in previous IOS (12 and earlier) version.

    @implementation MasterViewController

    //....some methods

    • (BOOL) shouldAutomaticallyForwardAppearanceMethods { return YES; }

    // ...some methods

    @end

    0 讨论(0)
  • 2021-01-12 00:30

    Another case where this will not be called at launch time (yet may be called on when you return to the view) will be is if you have subclassed UINavigationController and your subclass overrides

    -(void)viewDidAppear:(BOOL)animated

    but fails to call [super viewDidAppear:animated];

    0 讨论(0)
  • 2021-01-12 00:35

    Presenting view controllers using presentModalViewController or segues or pushViewController should fix it.

    Alternatively, if for some reason you want to present your views without the built-in methods, in your own code you should be calling these methods manually. Something like this:

    [self addChildViewController:controller];
    BOOL animated = NO;
    [controller viewWillAppear:animated];
    [self.view insertSubview:controller.view atIndex:0];
    [controller viewDidAppear:animated];
    [controller didMoveToParentViewController:self];   
    
    0 讨论(0)
  • 2021-01-12 00:36

    In my case, viewDidAppear was not called, because i have made unwanted mistake in viewWillAppear method.

    -(void)viewWillAppear:(BOOL)animated {
        [super viewdidAppear:animated]; // this prevented my viewDidAppear method to be called
    }
    
    0 讨论(0)
  • 2021-01-12 00:36

    The only way I can reproduce the problem of child controllers not receiving appearance methods is if the container view controller does the following (which I'm sure you're not doing):

    - (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
    {
        return NO;
    }
    

    Perhaps you can try explicitly enabling this:

    - (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
    {
        return YES;
    }
    

    But my child view controllers definitely are getting the viewWillAppear calls (either if I explicitly automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers or if I omit this altogether.

    Update:

    Ok, looking at the comments under your original question, it appears that the issue is that the child controller (B) in question is, itself, a container view controller (which is perfectly acceptable) presenting another child controller (C). And this controller B's own child controller C is being removed and you're wondering why you're not getting viewWillAppear or viewDidAppear for the container controller B. Container controllers do not get these appearance methods when their children are removed (or, more accurately, since containers should remove children, not children removing themselves, when the container removes a child, it does not receive the appearance methods).

    If I've misunderstood the situation, let me know.

    0 讨论(0)
  • 2021-01-12 00:38

    Had a same problem My container view controller did retain a child view controller via a property, but did not add a child view controller to its childViewControllers array.

    My solution was to add this line of code in the container view controller

    [self addChildViewController: childViewController];
    

    After that UIKit started forwarding appearance methods to my child view controller just as expected

    I also changed the property attribute from strong to weak just for beauty

    0 讨论(0)
提交回复
热议问题