Passing data from modal navigation controller to parent controller?
I am starting an iPhone development and I am trying to make a contacts style controller to add items to a table. I have two controllers designed but I cannot figure out how to transfer data between them. How can I get data from a modal controller to its parent?
Just trying to call methods on parentViewController will not work (and results in compiler warnings and crashes). I considered migrating data from the controller itself (which will happen anyway, I'm just trying to keep things as simple as possible), but even then I still need to somehow tell the parent view to update its data. Again, how can I do this?
a source to share
I considered moving the data out of the controller itself (which will still happen
I think now is the time to follow this discussion and create a separate ContactList model object to hold your data.
Your modal view controller simply adds new Contacts to the ContactList.
Your TableViewController must respect the same "ContactList". Since items are added / removed to / from the "ContactList", your TableViewController simply adds and removes rows from its TableView.
This way you will be independent from each independent ViewController, your code will be more flexible, and adding / removing individual rows will be much more efficient than reloading the entire tableView.
a source to share
I had the same question and found this example code: http://developer.apple.com/iphone/library/samplecode/LocateMe/Introduction/Intro.html
Helped me a ton and was pretty easy to understand from the code.
a source to share
In short, use a delegate.
I would suggest that you take a look at Lecture 11: Text Input, Content Presentation on Fashion (May 6) - an iPhone app programming course offered by Stanford. Find it on iTunes U.
Download this sample app if you want to know how to implement a delegate: http://www.stanford.edu/class/cs193p/downloads/11-Pickers.zip
a source to share