iPhone - nil button outside the method?
<p>I am creating a button like this inside a method:</p>

<pre><code>UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 100, 50);
[btn setTitle:@"Hello, world!" forState:UIControlStateNormal];
[self.view addSubview:btn];

myButton = btn; 
// I am saving the btn reference to this ivar declared on .h as UIButton.
</code></pre>

<p>At another point of the code I try to use myButton and it is always nil.</p>

<p>I have tried to retain btn after assigning it to myButton on the original method but myButton is always nil.</p>

<p>self.view is always there.
btn is never released.</p>

<p>Why myButton is nil?</p>

<p>I know I can create the button using alloc, but I am just trying to understand this.</p>

<p>thanks.</p>
