简体   繁体   English

awakeFromNib中有哪些网点?

[英]What are outlets in awakeFromNib?

I see that when view controller is loaded from storyboard, these events happen in order 我看到当从情节提要加载视图控制器时,这些事件按顺序发生

  • awakeAfterUsingCoder awakeAfterUsingCoder
  • awakeFromNib awakeFromNib
  • viewDidLoad viewDidLoad中

In awakeFromNib, I see that isViewLoaded == false. 在awakeFromNib中,我看到isViewLoaded == false。 From Which should I use, -awakeFromNib or -viewDidLoad? -awakeFromNib或-viewDidLoad应该哪个使用?

awakeFromNib is called when the controller itself is unarchived from a nib. 当控制器本身未从笔尖存档时,将调用awakeFromNib。 viewDidLoad is called when the view is created/unarchived. 创建/取消存档视图时将调用viewDidLoad。 This distinction is especially important when the controller's view is stored in a separate nib file. 当控制器的视图存储在单独的nib文件中时,这一区别尤其重要。

In the spec of awakeFromNib awakeFromNib的规格中

The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. 笔尖加载基础结构向从笔尖存档重新创建的每个对象发送awakeFromNib消息,但是仅在存档中的所有对象均已加载并初始化之后。 When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established . 当对象收到awakeFromNib消息时, 可以确保已建立其所有出口和动作连接

So which outlet and action does it mention? 那么,它提到了哪些出口和行动? The other thing is that awakeAfterUsingCoder is called 3 times in my case !!! 另一件事是在我的情况下awakeAfterUsingCoder被调用了3次!

This only works with nibs. 这仅适用于笔尖。 As I understand if we're loading ViewControllers from storyboard awakeFromNib gets called but before the view and subviews are initialised. 据我了解,如果我们从情节提要加载ViewControllers,则会调用awakeFromNib,但是在初始化视图和子视图之前。 That's why there is no guarantee that the view and outlets will be initialised. 这就是为什么不能保证视图和出口将被初始化的原因。 So if you need the object with established outlet and action connections you need to start awakeFromNib with [self view] it`s like a little trick that helps. 因此,如果您需要具有已建立的插座和动作连接的对象,则需要使用[自视图]启动awakeFromNib,这就像一个帮助您的小技巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM