我在另一篇文章(如何关闭操作表)上读到,我可以使用
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
为了使用定义在中的关闭按钮,来关闭 uiactionsheet:
UIActionSheet *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 = 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];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
[closeButton release];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
然而,我不确定将这行代码放在哪里,是否能解决我的问题:
然而,我不确定把这一行放在哪里可以解决我的问题。
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
此外,当我点击关闭按钮时,应用程序崩溃,并显示错误消息“PROGRAM RECEIVED ERROR MESSAGE SIGBRT”。我认为这两个问题有关。有人可以提供帮助吗?
-(void)dismissActionSheet:(id)sender
吗?你在按钮的addTarget
方法中定义了它。如果你告诉它选择器是dismissActionSheet:
,那么你也必须编写一个;-)。在这个方法中,调用dismissWithClickedButtonIndex:animated:
。--清楚了吗? - Mundiid
),所以你需要进行强制类型转换。请参考我回答的编辑部分。 - Mundi