UIViewController viewWillAppear not called when adding as subView

前端 未结 8 1402
野性不改
野性不改 2020-12-14 06:43

I have a UIViewController that I am loading from inside another view controller and then adding its view to a UIScrollView.

self.st         


        
相关标签:
8条回答
  • 2020-12-14 07:25

    I can't understand your questions and your description. My problem was similar to this only.

    CustomTabBarController -> CustomUINavigationController -> RootViewcontroller

    viewWillAppear of CustomUINavigationController and RootViewController are not getting called unless you switched to another tab and come back.

    The solution is call super.viewWillAppear(animated: true)

    override func viewWillAppear(_ animated: Bool) {
        **super.viewWillAppear(true)**
    }
    

    I struggled for more than a day for this small mistake.

    0 讨论(0)
  • 2020-12-14 07:26

    By default, appearance callbacks are automatically forwarded to children. It's determined with shouldAutomaticallyForwardAppearanceMethods property. Check value of this propery, if it's NO and if your child viewController should appear right on container's appearance, you should notify child with following methods in container's controller life-cycle implementation:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        for (UIViewController *child in self.childViewControllers) {
            [child beginAppearanceTransition:YES animated:animated];
        }
    }
    
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [self.child endAppearanceTransition];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
        for (UIViewController *child in self.childViewControllers) {
            [child beginAppearanceTransition:NO animated:animated];
        }
    }
    
    - (void)viewDidDisappear:(BOOL)animated {
        [super viewDidDisappear:animated];
        [self.child endAppearanceTransition];
    }
    

    Customizing Appearance and Rotation Callback Behavior

    Fixed my problem! Hope it would be helpful.

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