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.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
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 theviewWillAppear:
event.The
viewWillDisappear:
event is fired right before the view is going to disappear, andviewWillAppear:
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
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
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.