我有一个类变量,它是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];
}
答案 0 :(得分:2)
方法dismissActionSheet
没有任何参数,因此@selector
应如下所示:
[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventTouchUpInside];