How to save the option selected in UIPickerView and Load it back up
i just made a UIPickerView showing all of the countries. but when i leave the page and go back its back at the top. is there a easy w开发者_JAVA技巧ay like NSUserdefaults to save the option?
You could call inside viewWillDisappear of your UIViewController to get the current country
- (NSInteger)selectedRowInComponent:(NSInteger)component
Then convert the NSInteger to a NSNumber and save it with NSUserDefaults.
And when it's coming back to the view in the view controller's viewWillAppear or viewDidLoad (depending on your project) you could retrieve the NSInteger from the defaults and use it to call
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
Set the animated BOOL to NO if you don't want an animation every time you enter in that view.
Hope this helps
精彩评论