3

I'm making a split-view based iPad application(Portrait mode only), and I want to know how to recover initial state after viewDidUnload is called.

When split-view application started for the first time, -splitViewController:willHideViewController:withBarButtonItem:forPopoverController: is called automatically (right after -viewDidLoad). I prepares UIBarButtonItems in the method.

If I open modal dialog or something with UIWebViewController (it consumes a lot of memory), application receives memory warning, viewDidUnload(s) are called.

When I close the modal dialog, -viewDidLoad is called automatically, but this time -splitViewController:willHideViewController:withBarButtonItem:forPopoverController: is not called.

I prepares UIBarButtonItems in -splitViewController:willHideViewController:withBarButtonItem:forPopoverController: but it is not called, so buttons are dismissed.

In that case, should I call the method manually?

I found similar posting here. https://github.com/grgcombs/IntelligentSplitViewController/issues/6

Thanks.

Mark Coleman
  • 40,542
  • 9
  • 81
  • 101
tokentoken
  • 682
  • 7
  • 15
  • You should almost always configure your UI in viewDidLoad. Where do you put these UIBarButtonItems after you create them? – Filip Radelic Aug 06 '11 at 00:13
  • That is done in splitViewController:willHideViewController:withBarButtonItem:forPopoverController: Could you create a split-view based project? You can find no implementation in viewDidLoad. I suppose it is because to change the buttons dynamically. – tokentoken Aug 06 '11 at 02:37

1 Answers1

3

I don't know it is OK to answer to my own question, but maybe I found an answer for this.
http://osdir.com/ml/cocoa-dev/2011-02/msg00430.html

It says that we should preserve BarButtonItems in viewDidUnload, and load it in viewDidLoad.

It seems working fine.

- (void)viewDidUnload {
   [super viewDidUnload];
   self.toolbarItems = self.toolbar.items; // property with retain policy
}

- (void)viewDidLoad {
   [super viewDidLoad];
   if (self.toolbarItems) {
      self.toolbar.items = self.toolbarItems;
      self.toolbarItems = nil;
   }
}
tokentoken
  • 682
  • 7
  • 15