开发者

how to share data between views with navigation controller iphone

开发者 https://www.devze.com 2023-03-09 13:27 出处:网络
i have a vi开发者_运维问答ew 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

i have a vi开发者_运维问答ew 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.


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.


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.

0

精彩评论

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

关注公众号