简体   繁体   中英

how to share data between views with navigation controller iphone

i have a view which is fetching data from an Array and presenting the data in a tableview. This view has a navigation controller with a button in it. The button is meant to take you to another view for advanced searching. Let's say that in this new view i have a picker, when the user selects a value from the picker and clicks the back button in the navigation bar i want to get the value that the user selected. What is the best practice to do that? How can i send the selected value from one activity to the previous one?

Thanks in advance.

Use delegation. Write your own protocol like "PickerViewDelegate". then implement this protocol in your "main view" (which has table view). in PickerView just invoke [delegate somethingPicked:something].

I'm not sure, that search value is a model entity.

What you need here is reasoning a bit in terms of the Model-View-Controller design pattern.

Views should get their data through the model. So in your advanced search view, when the user selects some value, this value is stored in the model.

When you go back, the first view redraw itself by reading the current search value from the model.

There are other possibilities, like having the search view controller own a pointer to the first view and sending a message to it when the search value changes, but this is not very modular and is pretty fragile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM