I have a settings view controller which I have got a segue for and thats fine, after the user has go ne into the settings VC and amended there settings how would i get these settings to the main view controller. Is there a segue the 'other way' possible?
-
3Especially for this case (settings), maybe it would be more appropriate to persist the data into `NSUserDefaults` instead of just passing them between controllers. – Alladinian Mar 04 '14 at 13:55
4 Answers
You must use delegate protocol, this answer is perfect for your question

- 1
- 1

- 2,369
- 22
- 19
You can use Unwind segue. Check the following tutorial to learn about unwind segue.
http://chrisrisner.com/Unwinding-with-iOS-and-Storyboards
What are Unwind segues for and how do you use them?
You can also use NSNotificationcenter to transfer data from a view controller to another.
In case of settings, NSUserdefaults is the preferred way to do it.

- 1
- 1

- 525
- 2
- 8
You have several options here, basically you'd need an strategy to communicate data from your settings view controller to your main view controller. I'd prefer to do it independently from the segue executed. You could:
- Use NSUserDefaults to persist your already selected settings. Class Reference.
- Use Delegation technique to communicate results to another object in your app.
- Use Notifications to spread events / changes to a set of objects in you app.
- Use your own model to keep persistence of the changes if those are too much complex to be saved to user defaults.

- 1,057
- 5
- 18
You can also try using blocks. Put a property on your settingsViewController like so:
@property (nonatomic, strong) void(^completionBlock)(NSDictionary *dataYouWantPassedBack);
Then in your MainViewController, in -prepareForSegue set up what you want to happen to the data when you dismiss your settingsViewController
-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"mySegueName"])
{
SettingsViewController *dest = [segue destinationViewController];
dest.completionBlock = ^(NSDictionary *dataYouWantPassedBack){
//do anything you want with the data in the dictionary here
};
}
}
In settings view controller you can put your data into a dictionary that you want passed back and then call the completion block and pass the dictionary before you dismiss the view controller.
NSDictionary *example = [NSDictionary dictionaryWithObjectsAndKeys: obj, key, nil];
if (self.completionBlock)
self.completionBlock(example);

- 4,384
- 27
- 27