【问题标题】:how to dismiss action sheet如何关闭操作表
【发布时间】:2011-04-20 06:36:07
【问题描述】:

我使用此代码在 uiactionsheet 中显示 uipicker,但是当我单击关闭按钮时,我想从视图中删除操作表。那么删除actionSheet表单视图的代码应该是什么。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 40, 0, 0);

pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;

[actionSheet addSubview:pickerView];
[pickerView release];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[closeButton release];

[actionSheet showInView:self.view];//[UIApplication mainWindow]];

[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
 return false;
}

【问题讨论】:

标签: objective-c iphone-sdk-3.0 uipickerview


【解决方案1】:

您需要做的就是关闭 ActionSheet,您可以使用 dismissWithClickedButtonIndex:animated: 完成此操作

【讨论】:

  • 斯威夫特呢?
【解决方案2】:

添加此方法对我有用:

    -(void) dismissActionSheet:(id)sender {
        UIActionSheet *actionSheet =  (UIActionSheet *)[(UIView *)sender superview];
        [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    }

【讨论】:

  • 我的发件人是一个 UIBarButtonItem,它被添加到一个可变数组中,该数组被添加到一个 UIToolBar,它作为子视图添加到操作表中。如何在dismiss方法中访问actionsheet?
【解决方案3】:

操作表范围问题。

使用[actionSheet dismissWithClickedButtonIndex:0 animated:YES];

【讨论】:

  • 你在哪里用的?我尝试创建一个dismissActionSheet 方法,并将[actionSheetdismissWith...] 放入其中,但它似乎不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-21
  • 1970-01-01
  • 2013-07-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多