This question already has an answer here:
- Passing Data between View Controllers 42 answers
This is the scene of my storyboard.
UINavigationController
-> UITableViewController
-> push segue -> UIViewController
I know how to pass the data of UITableViewController
to UIViewController
.
But, how can I pass the data back to the UITableViewController
?(UIViewController
has a navigation bar with a back button)
You can do it through the use of delegation.
When you pass data of
UITableViewController
toUIViewController
, you can set a delegate onUIViewController
. Whenever you want to pass data back toUITableViewController
, you can call the delegate and pass in the dataHere's a more concrete example in code
Create a method on
UITableViewController
that takes data fromUIViewController
(example:-(void)processDataFromUIViewController:(NSString *)string
)Now when you want to pass data back to
UITableViewController
, call[delegate sendDataFromUIViewController:@"data"]