当子类化 UIViewController 时,什么会调用 viewDidLoad?
在将协议和委托进一步扩展到 UIKit 框架的实现中时,我试图了解协议和委托。
根据我对此 stackoverflow post 的理解,委托方法通常会有 Did , 应该 &意志就在它的名字里。
基于此,我假设 UIViewController.h 中声明的 - (void)viewDidLoad;
是一个委托方法,但是是什么以及来自哪里?
我查看了 UIViewController 的头文件,它只遵守 NSCoding 协议,这是一个死胡同。据我所知,UIViewController 的超类 UIResponder 也是一个死胡同。
我在这里使用 viewDidLoad 作为示例,但这可以适用于任何“Did”、“Should”和“Should”。将 UIViewController 中的方法。
这只是指南中的例外情况之一还是我遗漏了什么?
Trying to get my head around protocols and delegates when extending it further into the UIKit framework's implementation.
From my understanding of this stackoverflow post a delegate method will usually have Did, Should & Will in it's name.
Based on this, I would assume that - (void)viewDidLoad;
declared in UIViewController.h is a delegate method, but of what and from where?
I've looked at UIViewController's header file and it only adhere's to the NSCoding protocol which is a dead end. UIViewController's superclass UIResponder is also a dead end as far as I can see.
I've used viewDidLoad as an example here but this could apply to any of the Did, Should & Will methods in UIViewController.
Is this simply one of those cases that is an exception to the guidelines or am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“did”、“should”和“will”这些词通常用来描述何时调用一个方法,是否询问它是否“应该”做某事,为您提供一个在“将”发生某些事情之前运行代码的钩子,或者作为“确实”发生时的回调,这些词通常在委托和回调方法中使用,
当您的 .nib 文件已加载到内存中,并且您的 IBOutlet 已实例化并连接并准备就绪时 。用于配置。如果您打算子类化 UIViewController(如果您想知道的话),则无需担心自己调用它。
"did", "should", and "will" are words usually used to describe when a method is called, whether it is asking if it "should" do something", giving you a hook to run code before something "will" happen, or as a callback when something "did" happen. these words are usually used in delegate and callback methods.
viewDidLoad is called when your .nib file has been loaded into memory, and your IBOutlets have been instantiated and hooked up, and are ready for configuration. you don't need to worry about calling it yourself if you intend to subclass UIViewController, if that's what you're wondering.