如何解雇行动表

时间:2011-04-20 06:36:08

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

我使用此代码在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;
}

3 个答案:

答案 0 :(得分:11)

您需要做的只是关闭ActionSheet,您可以使用dismissWithClickedButtonIndex:animated:

答案 1 :(得分:7)

添加此方法对我有用:

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

答案 2 :(得分:4)

行动单范围问题。

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