Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did some debugging and here's what I found about the <code>ViewController</code> loading order:</p> <pre><code>initWithNibName:bundle: self = &lt;original instance&gt;, retainedOutlet = 0x0 loadView &gt;&gt;&gt; self = &lt;original instance&gt;, retainedOutlet = 0x0 initWithCoder: self = &lt;coder instance&gt;, retainedOutlet = 0x0 initWithCoder: self = &lt;coder instance&gt;, retainedOutlet = 0x0 setView: self = &lt;original instance&gt;, retainedOutlet = 0x0 setRetainedOutlet: self = &lt;original instance&gt;, retainedOutlet = 0x1613c40 viewDidLoad self = &lt;coder instance&gt;, retainedOutlet = 0x0 awakeFromNib self = &lt;coder instance&gt;, retainedOutlet = 0x0 loadView &lt;&lt;&lt; viewDidLoad self = &lt;original instance&gt;, retainedOutlet = 0x1613c40 viewWillAppear: self = &lt;original instance&gt;, retainedOutlet = 0x1613c40 dealloc self = &lt;coder instance&gt;, retainedOutlet = 0x0 viewDidAppear: self = &lt;original instance&gt;, retainedOutlet = 0x1613c40 </code></pre> <p>During the loadView method, <code>initWithCoder:</code> is called and a new copy of the <code>viewController</code> is created. this is what is passed into a few of the methods (like <code>viewDidLoad</code>). the copy is destroyed later in a dealloc call. the good news is that in this copy, retained outlets are not configured, so you can use this as a test to know if you should initialize variables, call other methods, and most importantly, if you should release and destroy objects during dealloc.</p> <p>Key takeaway: the real <code>viewController</code> will have its retained <code>IBOutlet</code> properties configured. if you are in an overridden method that is getting called multiple times, just check one of your retained <code>IBOutlet</code> properties for <code>NULL</code>. if they are <code>NULL</code>, then return immediately.</p> <p>Anybody got any clues as to why this is happening this way?</p> <p>Side effect of this: you can't use <code>awakeFromNib</code> reliably.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload