views:

302

answers:

2

Hi guys,

I have an iPhone application. First view controller which is a UITableViewController has a cell for "category". When user select "category" it will push another UITableViewController where user can select category.

I have done both view controllers but when you click back(usually the title of table) button on navigation bar it clears off selection. I also need to pass selected category to back view controller. What is the proper way to implement that so when you click back on navigation bar it will remember your selection and populate the selected in the back view controller's "category" cell.

An example of this can be found in ebay application. When you search for something in ebay iphone application you have "Refine" button on top right. When you click this you can further refine the category. I'm trying to achieve exactly like this.

Thanks

A: 

Hi, If you want to memorize a selection do not use the selected property as permanent state. It's not made for that.

Blue Selection of tableViewCell must be used only for temporary user feed back when touched. Implement the didDeselectRowAtIndexPath: of the delegate (maybe self) and then deselect immediately your cell while you set the right indicatorStyle to checkmark and simultaneously set the variable of your data model object to record the state.

I guess you have initialized your category view controller by passing a data object as argument. This object will be modified when the user change the category and used after by the parent controller. Maybe I'm not clear enough. ;) Does it answer ? Vincent.

Vincent Zgueb
A: 

You need a data model.

A data model is a dedicated object that holds the data of your application. When a view controller displays its view, it checks the data model for the data it needs to display. When it changes data, it writes that to the data model. When the next view controller displays, it checks the data model and loads the data it needs. At no time do the view controllers talk to each other directly.

If you have a small amount of data you can park it as attributes of the app delegate. For more complex data you should have a dedicated object.

TechZen
I am using app delegate at the moment as data is small enough. But when you click back button on navigation bar it simply take you back to parent controller. Question here is how can I make parent reload that information from app delegate?
Leo
Put the fetching of the data in viewWillDisplay. That will force the table to reload it every time the view displays.
TechZen