Obj-C, showing a UIPickerView in an UIActionSheet, but need to save to NSUserDefaults and refresh table contents, but where?

天涯浪子 提交于 2020-01-17 01:17:30

问题


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];
}

回答1:


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.



来源:https://stackoverflow.com/questions/7464302/obj-c-showing-a-uipickerview-in-an-uiactionsheet-but-need-to-save-to-nsuserdef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!