views:

509

answers:

1

I have a very simple scenario:

My iPhone application contains a UIViewController implementation which displays a list of items. In its navigation bar there is a button for adding items to that list. When this button is clicked, a new UIViewController is instantiated and presented on the screen using:

[self presentModalViewController:controller animated:YES];

This controller contains views that take user input for a new item in the list. After the user is done entering information, he clicks the "Done" button.

The "Done" button should take all entered information and return it to the first controller (the one displaying the list). The first controller could then add an item to its list based on the information that was just entered.

My question is: How do I send back the information from the second controller to the first controller in a nice fashion?

+1  A: 

You can use protocols...In your modal view controller you can define a protocol that must be implemented by its delegate say the method -(void)userDidEnterInfo:(some sort of info), in your view controller that you want to pass the info to you can conform to the protocol and become the view controllers delegate...right before you dismiss or whenever you are r eady to send the info over you can call [delegate userDidEnterInfo:] and the view controller will receive the information...Heres more on protocols http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html#//apple%5Fref/doc/uid/TP30001163-CH15

Daniel
Thank you. That's what I was looking for!
Tom van Zummeren
Correct answer, would have been nice with code example. And explanation why you should avoid circular dependencies.
PeyloW
theres example in the guide i provided, no need for me to provide code...its straight forward
Daniel