调用顺序 init,loadView,viewDidLoad,viewWillAppear
2. viewDidUnload
在栈导航中返回上一层时,本页的dealloc调用了,viewDidUnload也没有调用。
当内存警告时,会调用viewDidUnload,要在这里选择做一些释放内存的操作。再加载这个页面时,会重新调用loadView,viewDidLoad。viewController.view将会被重新构建。
不用重写didReceiveMemoryWarning
调用键盘等耗内存大时,会收到- (void)didReceiveMemoryWarning ,但不用重写didReceiveMemoryWarning,要在- (void)viewDidUnload 中选择释放一些内存。当再进入这个view controller时,系统会重新调用它的loadView,viewDidLoad。
dealloc后此viewcontroller不会再重用了,但viewDidUnload后此viewcontroller还是要重用的,所以要注意在viewDidUnload中选择释放内存,并置nil。
测试依次调用了applicationDidReceiveMemoryWarning,UITabBarController的didReceiveMemoryWarning,以及第一个tab项ViewController的didReceiveMemoryWarning和viewDidUnload,以及其它ab项ViewController的didReceiveMemoryWarning,及其它子viewController的didReceiveMemoryWarning.
即会调用活着的viewController的didReceiveMemoryWarning,选择调用它们的viewDidUnload。
loadView,viewDidLoad不能认为在viewController生命周期内只会被调用一次。一些内容可以不在viewDidUnload中释放,但要在loadView中做好保护。
3.关于 ios5中UIViewController addChildViewController新方法的使用
http://wangjun.easymorse.com/?p=1630
4.presentModalViewController上升效果与父UIViewController的view的尺寸有关
presentModalViewController的时候,它会以window作为底色,所以设置alpha的时候会出现白色
5.UIInterfaceOrientation interfaceOrientation 属性,可能这个值在使用过程中不准确,还是使用[[UIApplication sharedApplication] statusBarOrientation];替代。
在UIViewController初始化过程中 self.interfaceOrientation;准确,但在方向变化后,self.interfaceOrientation可能没有被更新,这时要使用[[UIApplication sharedApplication] statusBarOrientation];
6.parentViewController 属性
/*
If this view controller is a child of a containing view controller (e.g. a navigation controller or tab bar
controller,) this is the containing view controller. Note that as of 5.0 this no longer will return the
presenting view controller.
*/
@property(nonatomic,readonly) UIViewController *parentViewController;
如果viewController中导航中,parentViewController返回的是navigation controller实例。
7.navigationController属性
self.navigationController可能返回的是self.parentViewController成员,或者返回的是self.parentViewController.parentViewController,直到找到类型UINavigationController。
7.In practice, on any modern (3.0+) iOS, all three methods are sent to the view controller of the actively-shown view.
The methods are called in the order listed:
willRotateToInterfaceOrientation:duration: first
willAnimateRotationToInterfaceOrientation:duration: second,
didRotateFromInterfaceOrientation: last
Note: iOS 5 deprecates the other rotation-notification methods (dealing with the two-step animation process), so these three are the only ones that should be used in new projects.
http://stackoverflow.com/questions/2521273/what-are-the-differences-between-the-interface-orientation-delegate-methods
8.ios6中,当一个ViewController的view赋值给另一个ViewController的view时,运行报错: A view can only be associated with at most one view controller at a time。