1. loadView 和 ViewDidLoad 区别:
就是当view的nib文件为nil时,手工创建视图界面时调用loadVIew;
当view的nib文件存在的时候,初始化工作在viewDidLoad中实现
但是如果你的程序运行期间内存不足,视图控制器接到didReceiveMemoryWarning消息时,那么此时系统默认操作会检查当前视图控制器的view是否还在使用,
假如此view不在当前正在使用的view hierarchy里面,且控制器实现了 loadView方法,那么这个view将被release, loadView方法将被再次调用来创建一个新的view。
---所以,当使用了nib时,不能实现loadview(rainy,否则会报错)
下面有比较全面的说法。
Creating a UIViewController’s UI in code (no .xib, no storyboard)
Override the method - (void)loadView and set self.view to something.
This is either/or with storyboards/.xibs.
Do NOT implement loadView if you use a storyboard/.xib to create the UIViewController.
Do NOT set self.view anywhere else besides in loadView.
Do NOT implement loadView without setting self.view (i.e. you must set self.view in loadView).
--不使用.xib和stroyboard时,需要覆盖loadView方法,且设置self.view:
1. 如果使用了.xib或者storyboard,绝对不可以实现loadview方法;
2. 除了loadview方法之外,绝对不要在其他的地方设置self.view;
3. 一定得在loadview中设置self.view;
就是当view的nib文件为nil时,手工创建视图界面时调用loadVIew;
当view的nib文件存在的时候,初始化工作在viewDidLoad中实现
但是如果你的程序运行期间内存不足,视图控制器接到didReceiveMemoryWarning消息时,那么此时系统默认操作会检查当前视图控制器的view是否还在使用,
假如此view不在当前正在使用的view hierarchy里面,且控制器实现了 loadView方法,那么这个view将被release, loadView方法将被再次调用来创建一个新的view。
---所以,当使用了nib时,不能实现loadview(rainy,否则会报错)
下面有比较全面的说法。
Creating a UIViewController’s UI in code (no .xib, no storyboard)
Override the method - (void)loadView and set self.view to something.
This is either/or with storyboards/.xibs.
Do NOT implement loadView if you use a storyboard/.xib to create the UIViewController.
Do NOT set self.view anywhere else besides in loadView.
Do NOT implement loadView without setting self.view (i.e. you must set self.view in loadView).
--不使用.xib和stroyboard时,需要覆盖loadView方法,且设置self.view:
1. 如果使用了.xib或者storyboard,绝对不可以实现loadview方法;
2. 除了loadview方法之外,绝对不要在其他的地方设置self.view;
3. 一定得在loadview中设置self.view;