开发者

How to recover from viewDidUnload(after memory warnings), using UISplitViewController

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 tha开发者_如何学Pythont case, should I call the method manually?

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

Thanks.


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;
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜