iOS: different addSubview behavior between iOS 4.3 and 5.0

前端 未结 7 2040
长发绾君心
长发绾君心 2021-01-30 11:32

while coding in iOS 4.3 before, I found while add a view controller\'s view to another view with [superview addSubView:controller.view], the controller instance wil

7条回答
  •  遇见更好的自我
    2021-01-30 11:51

    This may not be an answer what you want, but I had same kind of problem.

    In my case, when I added a view controller's view to another view controller's view as a subview, the subview was received viewWillAppear only in iOS 5.0 not iOS 4.X.

    So I added a nasty condition.

    [self.view addSubview:self.viewController.view];
    if ([[[UIDevice currentDevice] systemVersion] compare:@"5.0"] == NSOrderedAscending) {
        [self.viewController viewWillAppear:animated];
    }
    

    From iOS 5.0, Apple provides a way to implement custom container view controllers like UINavigationController or UITabController. I think this change affects when viewWillAppear is called.

    This problem may be solvable if we use -[UIViewController addChildViewController:].

提交回复
热议问题