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.
开发者_如何学GoThe "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?
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_ref/doc/uid/TP30001163-CH15
精彩评论