开发者

iphone How to implement a view used in multiple places?

In my specific example I have a navigation controller inside tab 2 of a tab bar controller, the root navigation controller view has three buttons: 'nearest store' - this pushes a view that contains a mapview with nearest stores, clicking the store pins will push the store details view. 'all stores' - this pushes a view that contains a tableview that lists all the stores, clicking on a row will push the store details view. 'store search' - this pushes a view that contains a text box which allows a town/postcode search for nearest stores which appear in a tableview, clicking on a row will push the store details view.

The issue I have is how should the store details view be implemented since it will be pushed onto from multiple parent views.

I currently have each parent view, nearest store view, all stores view, store search view, contain a seperate instance of the store details view controller which is allocated memory and pushed onto the view controller as necessary. My worry is that if I access the store details view through each of these 3 paths then there will be 3 copies of the store details in memory since I am not sure when these will be automatically released.

My think开发者_高级运维ing was that an alternative way of implementing this is to have an instance of the store details view controller from the primary navigation root controller with the three buttons. From any of the nearest store, all store, store search views, if the store details view needs to be accessed then the current view is popped off the navigation controller and a method in the root controller will be run to push the store details view on. This will mean that there will only ever be one instance of the store details view in memory since it will be reused everytime it is accessed.

Since the popping and pushing to get to the store details view will not be animated, it may be confusing for the user when they click the back button as they will end up on the root view controller and not the view they were previously on.

Is this a good way to implement this view structure? I am not sure I understand how the iPhone keeps views in memory and if going down this alternate route will be beneficial or a waste of time.

Thanks for any help.


What I would do (may not be right) is have a tab bar controller and the three different store search views under each of the tabs.
Then have a singleton view object which will be your details view. Therefore all three of the views can access the same details view object.
Hope I kinda helped :S

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜