Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>* EDIT *</strong> and futher explanation. Using self.currentView as Rob suggested has to be done as well.</p> <p>I'd suggest</p> <pre><code>@property(nonatomic,strong) UIView* currentView; </code></pre> <p>and now a shorter version which does the same</p> <pre><code>[self.currentView removeFromSuperView]; </code></pre> <p>now what currentView is pointing to is not in the view hiearchy anymore, but not yet deallocated, because we have a strong reference to it. If we had declared it as "weak" or "__unsafe_unretained", it would get deallocated by the system at an unknown time in the future (or maybe right away – depending on the iOS version).</p> <pre><code>self.currentView = [[SomeView alloc]initWithFrame:self.bounds]; self.currentView.delegate = self; </code></pre> <p>This does a few things.<br> The old self.currentView is released by the system, because the superview does't have a reference to it anymore (was removed from superview by us)<br> SomeView is created, the pointer assigned to self.currentView and retained – current retain count: 2, without ARC, we would have lost one pointer here....</p> <pre><code>[self.view addSubview:self.currentView]; </code></pre> <p>This will add the view to the hierarchy, which will increase the retain count to 3. (one that the superview is going to hold, one for our strong property and one from the dnagling alloc/init). At the end of the scope, ARC will release the one from alloc/init, retain count now: 2</p> <p>So there is no need to do anyting funky in -dealloc. Even with ARC it makes sense to keep track (conceptually) of the retain counts.</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