title: UISegmentedControl in UINavigationBar disappears when UIViewControllers are not constantly re-instantiated
body: <p>I use a UISegmentedControl in the navigation bar to switch between UIViewControllers in my application. However, the UISegmentedControl disappears from the navigation bar after I switch UIViewControls more than once. This only happens when the view controls are not initialized and allocated anew each time the segmented control is pressed. In other words, if I allocate a new UIViewController each time I want to switch views in my app, the expected behavior is observed (eg, UISegmentedControl doesn't disappear). However, this is not a practical solution since I want to save the hidden view's state when the user switches views.</p>
  
  <p>I have <a href="https://github.com/aashidham/UISegmentedControl-View-Switching/commit/d416292b48148e49db3674b4bb0c06121a9b43fc#diff-0" rel="nofollow">here</a> a repo of a simple project where this is observed. The project consists of two commits: the older where this problem is observed, and the newer where the problem is 'solved' by constant re-instantiation.  </p>
  
  <hr>
  
  <p>More detail about the earlier commit in this repo:</p>
  
  <p>The <code>didFinishLaunchingWithOptions</code> in the accountingAppDelegate is where the two view     controllers for the application (RootViewController and CalendarViewController) are both instantiated for the lifetime of the application.</p>
  
  <p>The UISegmentedControl is loaded from a NIB file named SegmentedControl.xib in the <code>didFinishLaunchingWithOptions</code> method.</p>
  
  <p>The <code>toolBarItems</code> method in the accountingAppDelegate is a convenience method for both viewcontroller's <code>viewDidAppear</code> methods, where the <code>toolbarItems</code> property of each viewcontroller is set. The UINavigationController looks at this property to assign the items in the navigation toolbar for the current view, from my understanding of <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html" rel="nofollow">the Apple docs</a> (look up "Displaying a Toolbar"). </p>
  
  <p>The only difference with the newer commit is that new instances of RootViewController and CalendarViewController are created each time the user switches from one to the other. </p>
  
  <hr>
  
  <p>My question is: why does constant re-instantiation solve the problem? And more importantly, can I prevent the UISegmentedControl from disappearing <em>and</em> preserve the view states of my application?</p>