I have a UITableviewController and I push another UIViewController in ‘didSelectRow..’ method.
I have user input controls (combobox, stepper) in this viewController, that when the UIViewController is popped , I would like to receive the newly entered data in the UITableviewController (and update the tableview accordingly).
I saw some questions/answers, and some said to use “Delegation/Protocol” approach, but did not find any specific example how to achieve this.
Can someone help?
Create a new file for your project and choose the Protocol file type. (We’ll call it
CallBackProtocol.) In the view controller that you push, create a property that has a type ofid<CallBackProtocol> delegate;. Have your table controller adopt the protocol and, when it creates the view controller, setcontroller.delegate = self;.Define a method in the protocol that lets you pass whatever data you need back to the caller. Implement that method in the table controller and call it from the second view controller just before popping it.
(Or use a
NSNotification.)