I was using pickerView didSelectRow
to save the selected value to NSUserDefaults and re populate my table view. However, at the point the action sheet / picker view is still visible and the user can select new values and didSelectRow will be called again.
EDIT: To clarify I don't want to populate my table view at this point.
I'm looking for an event when I can save the value and re-populate after the picker view is dismissed.
What can I use ?
Here's my code to show the action sheet / picker view.
- (IBAction)btnClicked:(id)sender {
NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].
orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;
UIActionSheet *actionSheet = [[[[UIActionSheet alloc] init]
initWithTitle:[NSString stringWithFormat:@"%@%@",
title, NSLocalizedString(@"Select the recurrence", @"")] delegate:self
cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:@"OK", nil] autorelease开发者_如何转开发];
[actionSheet showInView:self.view];
UIPickerView *pickerView = [[[UIPickerView alloc] init] autorelease];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
}
If you are dismissing the action sheet using the OK button defined above then you can use the action sheet delegate method actionSheet:willDismissWithButtonIndex:
method. If you store the picker's selection in the picker view delegate methods, then write it to defaults when the action sheet is dismissed, this should cover you.
精彩评论