1

我有一个类变量,它是 的一个实例UIActionSheet,称为 actionSheet。我添加了一个实例UIPickerView以及一个实例UISegmentedControl。虽然当我点击“完成”按钮(UISegmentedControl 的实例)时,我的类方法dismissActionSheet 永远不会被调用。谁能帮我吗?

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

-(IBAction)chooseTopicButtonPressed{


    actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:nil
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

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

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

    [actionSheet addSubview:pickerView];


    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
    closeButton.momentary = YES;
    closeButton.frame = CGRectMake(10, 6, 300, 30);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blueColor];
    [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventTouchUpInside];


    //dismissActionSheet NOT BEING CALLED FOR SOME REASON!!! 

    [actionSheet addSubview:closeButton];

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];

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


-(void)dismissActionSheet{
    NSLog(@"dismissActionSheet called");
    [actionSheet dismissWithClickedButtonIndex:0 animated:YES];

}
4

1 回答 1

2

该方法dismissActionSheet没有任何参数,因此@selector应如下所示:

[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventTouchUpInside];
于 2012-11-06T22:19:35.910 回答