IPhone Navigation Controllers - Best practise for reusing views
Hi I use Navigation controllers a lot in my app but my apps starting to suffer from views calling the same views over and over and pushing them on the nav controller stack rather than reusing existing views on the stack.
For instance I have a map view thats called in various places in my app.
I should really go through t开发者_开发知识库he Nav Controller stack and find the mapview I pushed already and move it to the top of the stack.
Instead I create a new one and just push it on the top.
As my app gets more complicated Im sure ill get memory issues and users will get bored hitting the back button to get to the main menu.
Anyone got good example of finding a view in the Nav Controller stack.
How should I do it?
Do I need to keep a pointer to my Map View in App Delegate?
If there a way to find a view quickly in the stack or do I need to keep an index/NSDictionary to their location somewhere.
I noticed that whoever is writing the Facebook app now has the same problem. As notifications come in they open the app and instantiate the Notification view and push it on the stack. After a while you end up closing a whole pile of old notification windows to get back to main menu. cheers
If you want the particular viewcontroller on the top of stack, which you have already pushed on the stack, instead of creating one, you can use the following method.
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
If you know in advance the viewControllers will be pushed on the stack, you can push them at once with the below function, instead of pushing them again and again.
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
精彩评论