Obj-C,在UIActionSheet中显示UIPickerView,但是需要保存到NSUserDefaults并刷新表内容,但是在哪里? [英] Obj-C, showing a UIPickerView in an UIActionSheet, but need to save to NSUserDefaults and refresh table contents, but where?

查看:59
本文介绍了Obj-C,在UIActionSheet中显示UIPickerView,但是需要保存到NSUserDefaults并刷新表内容,但是在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pickerView didSelectRow 将所选值保存到NSUserDefaults并重新填充表视图。但是,此时操作表/选择器视图仍然可见,用户可以选择新值,并且将再次调用didSelectRow。

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.

编辑:为了澄清,我不知道我不想在这一点上填充表格视图。

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.

我可以使用什么?

这是我的代码,用于显示操作表/选择器视图。

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


推荐答案

如果您要取消该操作使用上面定义的确定按钮创建工作表,然后可以使用操作表委托方法 actionSheet:willDismissWithButtonIndex:方法。如果将选择器的选择存储在选择器视图委托方法中,然后在取消操作表时将选择器的选择内容写入默认值,这样就可以覆盖您。

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.

这篇关于Obj-C,在UIActionSheet中显示UIPickerView,但是需要保存到NSUserDefaults并刷新表内容,但是在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆