loadView:iOS UIView 中的函数
我不明白 loadView:
函数的机制(这个函数在 UIView 中)。
我创建了一个项目如下:
- 首先,我创建了一个iPhone的基于窗口的项目。
- 然后,我创建了一个
UIView
子类 - 接下来,我创建了一个
UIViewController
子类,没有 xib。 - 最后,在第三步中创建的类的 loadView: 函数中,我将 UIView 对象(在第二步中创建的类中)指定为 UIViewController 的视图变量 对象(在第三步中)。
如果我省略最后一步,并将语句 NSLog(@"test LoadView");
放在 loadView: 函数中,那么当项目运行时,语句 NSLog(@"test LoadView");
不断调用,导致运行溢出。
请给我解释一下!谢谢你!
I don't understand the mechanism of loadView:
function (this function is in UIView).
I created a project as below:
- First, I created a iPhone's window-based project.
- Then, I created a
UIView
subclass - Next, I created a
UIViewController
subclass, with no xib. - Lastly, in the
loadView:
function of the class I created in the third step, I designate the UIView object (in the class I created in the second step) as the view variable of theUIViewController
object (in the third step).
If I omit the last step, and place the statement NSLog(@"test LoadView");
in the loadView: function, then when the project is run, the statement NSLog(@"test LoadView");
is invoked continuously, result in the run is overflow.
Please explain me! Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
loadView:
仅在视图属性为nil
时调用。以编程方式创建视图时使用此选项。默认:
创建一个没有子视图的 UIView 对象。例如 -通过实现
loadView:
方法,您可以挂钩默认的内存管理行为。如果内存不足,视图控制器可能会收到didReceiveMemoryWarning
消息。默认实现检查视图是否正在使用。如果它的视图不在视图层次结构中并且视图控制器实现了 loadView: 方法,那么它的视图就会被释放。稍后,当需要视图时,会再次调用loadView:
方法来创建视图。不确定为什么要使用
loadView:
但你可以在viewDidLoad:
参考 -
希望这有帮助。
loadView:
is only invoked when the view property isnil
. Use this when creating views programmatically.default:
create a UIView object with no subviews. For ex -By implementing the
loadView:
method, you hook into the default memory management behavior. If memory is low, a view controller may receive thedidReceiveMemoryWarning
message. The default implementation checks to see if the view is in use. If its view is not in the view hierarchy and the view controller implements theloadView:
method, its view is released. Later when the view is needed, theloadView:
method is invoked again to create the view.Not sure why you want to use
loadView:
but you can do just as much inviewDidLoad:
Reference -
Hope this helps.