In IOS 4.x or lower, viewDidAppear method is not getting called while adding subview to a view, why?

后端 未结 2 1845
暗喜
暗喜 2021-01-17 16:08

In iOS 4.x or lower, viewDidAppear and viewWillAppear, viewDidDisappear and viewWillDisappear, such ViewController\'s delegate methods are not getting called. The same metho

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 17:13

    If your view controller is a child of another view controller, (i.e. it's a UINavigationController inside a UIViewController, or vice versa, etc.), the child's viewDidAppear, viewWillAppear, etc. methods will not get called. The solution is to have the parent call into them like:

    -(void)viewWillAppear:(BOOL)animated { 
        [super viewWillAppear:animated];
        [child viewWillAppear:animated];
    }
    

    I know this happens through iOS 4.3. In iOS 5 there is a new set of methods specifically for handling these cases: Implementing a Container View Controller

提交回复
热议问题