Pantelis Proios
Pantelis Proios

Reputation: 1369

Xcode : Storyboard and retaining data in each controller

As you can guess i am a new programmer and i have trouble getting a simple thing! I am making an app with multiple view controllers. Each controller have textfields and UIsegmentedControl items. When i am moving from one view controller to the other (uding modal trantition if that matters), the contents of the previous one (textfield entries and segmented control option) reset to their original state. How can i make them keep their previous state? Thanks in advance.

Upvotes: 5

Views: 3249

Answers (3)

user1199409
user1199409

Reputation: 34

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    bViewController *deneme = [segue destinationViewController];
    [deneme setPassedValue:label.text];
}

This piece of code will solve your problem, I hope. It saves the label of whatever is inside of it. And you need to add some more code to other classes.

If this code helps you tell me and I can give you the whole code.

Upvotes: 2

Diwann
Diwann

Reputation: 916

You can also use a navigation controller to move from one view to another. This way, you will push your new view on top of the previous one, and when you go back, the previous view has kept its state. see this tutorial for more information on storyboard and UINavigationController : http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

Upvotes: 0

Telmo Marques
Telmo Marques

Reputation: 5106

To save the application state you can use a model class, following the recommended MVC (model-view-controller) paradigm. More information here: Retain view state upon reloading

As an alternative you could use the viewWillDisappear: event to save your view state, and then restore it on the viewWillAppear: event.

The viewWillDisappear: event is fired right before the view is going to disappear, and viewWillAppear: is fired before the view is put on the foreground, being ideal to make any changes to the UI.

These events might have already been declared for you in your view controller, but in case they're not check the prototypes here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

Upvotes: 0

Related Questions