Objective c UIButton addTarget方法…不工作?
我有一个类变量,它是Objective c UIButton addTarget方法…不工作?,objective-c,ios,uisegmentedcontrol,uiactionsheet,Objective C,Ios,Uisegmentedcontrol,Uiactionsheet,我有一个类变量,它是UIActionSheet的一个实例,名为actionSheet。我添加了UIPickerView的实例以及UISegmentedControl的实例。尽管当我点击“完成”按钮(UISegmentedControl的实例)时,我的类方法dismissActionSheet从未被调用。有人能帮我吗 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -(IBAction)chooseTopicButtonPressed{ acti
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];
}
方法
dismissActionSheet
没有任何参数,因此@选择器应如下所示:
[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventTouchUpInside];
这是对控制的大量滥用。ui操作表
用于显示按钮菜单。UISegmentedControl
实际上并不打算用作常规案例按钮。总有一天,苹果可能会更新UIActionSheet
的实现,而每一个错误使用它的人都会遇到很多问题。尝试使用真正的UIButton而不是UISegmentedControl
,或者尝试使用UIActionSheet
中的一个按钮。