iOS: different addSubview behavior between iOS 4.3 and 5.0

前端 未结 7 2031
长发绾君心
长发绾君心 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:39

    view{Will,Did}Appear, view{Will,Did}Disappear are functions on View Controllers and not views. These functions are called by SDK provided view controllers that are supposed to manage other view controllers e.g. UITabBarController, UINavigationBarController.

    If you are managing sub-view controllers yourself, you have to call these explicitly (and in proper order - though you should have a very good reason to do this). A modal view not getting these calls upon dismissal of a modal view is simply because there is no one there to call it. Encapsulate the root view controller in a UINavigationController (and hide the navigation bar if you like) and then open a modal view controller. Upon its dismissal, or pop, viewWillAppear will get called.

提交回复
热议问题