开发者

How to set up an NSMutableArray to be accessed from different tabs

I have an app with a tab bar. Each tab has its own view controller. I also have a mutable array that each tab view controller should be able to access (get the ith element, add a new element, delete an element, etc). Right now, I'm doing an ugly hack, which is passing the array around as I change tabs with using things like this in the viewWillAppear and viewDidDisappear methods:

[[[[self.tabBarController viewControllers] objectAtIndex:2] viewControllers] objectAtIndex:0];

Please can someone enlighten me as to the correct way to do this? I have a feeling I 开发者_JS百科should just keep the array in my appdelegate, but I'm not sure how to access it from the other view controllers if I do that.

Many thanks!


I'm facing a similar issue. After looking around I decided for a singleton which declares the NSMutableArray in its @interface, and then is shared between all the viewControllers. I started from this page for the general shape. I'm then passing around calls to set up the values of the array. I'm not still 100% done (see this post of mine) but I think this should be the way. Any other ideas are most than welcome! Have a nice day! /Luca

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜