title: Popover deallocating content view controller directly after initialization
body: <p>I have a weird problem where a UIPopovercontroller is immediately deallocating its content view controller after loading the popover, and then reinitializing it.<br/> 
  My goal is to read a textField when the popover is being dismissed.</p>
  
  <p>My impression was that I create a UIViewController and set it as the content view controller for the popover. The PopoverViewController will then retain the content view controller and I can (auto)release it.<br/>
  Later, when the popover is being dismissed, it will release the popover (and with it the content view controller). But that's not working. This is my relevant code:</p>
  
  <pre><code>- (IBAction)popoverButton:(id)sender {
    // Create &amp; Initialize content view controller
    ContentViewController* cvc = [[[ContentViewController alloc] initWithNibName:@"ContentViewController" bundle:nil] autorelease];
  
    // Create, initialize and load popover
    popoverController = [[UIPopoverController alloc] initWithContentViewController:cvc];
    [popoverController setDelegate:self];
    [popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  
    NSLog(@"popoverButton: %@, retainCount: %d", cvc, [cvc retainCount]);
  }
  
  - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)senderPopoverController
  {
    NSLog(@"popover should dismiss");
    ContentViewController *dvc = (ContentViewController *)([popoverController contentViewController]);
    NSLog(@"%@ %@ %@", dvc, [dvc testTextfield], [[[dvc testTextfield] text] description]);
    return YES;
  }
  </code></pre>
  
  <p><strong>ContentViewController.m</strong></p>
  
  <pre><code>- (void)viewDidLoad
  {
    [super viewDidLoad];
    [[self testTextfield] setText:@"Bla"];
    NSLog(@"viewDidLoad: %@", testTextfield);
  }
  
  - (void)dealloc {
    NSLog(@"dealloc: %@", testTextfield);
    [testTextfield release];
    [super dealloc];
  }
  </code></pre>
  
  <p>When I open the popover, the Log would be (I think the order of the output does not represent the order when it is actually called):</p>
  
  <pre><code>Popover Test[2363:707] viewDidLoad: &lt;UITextField: 0x185750; ...&gt;
  Popover Test[2363:707] viewDidLoad: (null)
  Popover Test[2363:707] popoverButton: &lt;ContentViewController: 0x1844e0&gt;, retainCount: 4
  Popover Test[2363:707] dealloc: &lt;UITextField: 0x185750; ...&gt;
  </code></pre>
  
  <p>And when I dismiss it:</p>
  
  <pre><code>Popover Test[2363:707] popover should dismiss
  Popover Test[2363:707] &lt;ContentViewController: 0x1844e0&gt; (null) (null)
  Popover Test[2363:707] popover did dismiss
  Popover Test[2363:707] &lt;UIPopoverController: 0x184860&gt;
  Popover Test[2363:707] dealloc: (null)
  </code></pre>
  
  <p>So my questions would be:</p>
  
  <ol>
  <li>Why is the ContentViewController deallocated and initialized a second time?</li>
  <li>Why do the outlets (textField) not work anymore when its loaded the second time?</li>
  </ol>
  
  <p>If I could solve this, I would be able to read from the textField in <em>popoverControllershouldDismissPopover</em></p>