xcode 如何使用关闭按钮关闭 UIActionSheet 并避免崩溃?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8378514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to dismiss UIActionSheet with close button and avoid crash?
提问by Shaddy
I have read on another post (how to dismiss action sheet) that I can use
我已阅读另一篇文章(如何解除操作表),我可以使用
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
to dismiss the uiactionsheet with the close button, as defined in:
使用关闭按钮关闭 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)];
However, I am not sure where to place this line, assuming this will solve my problem:
但是,我不确定将这条线放在哪里,假设这将解决我的问题:
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
Also, the app crashes when I click the close button, with error message "PROGRAM RECEIVED ERROR MESSAGE SIGBRT". I assume my two problems are related. Any help out there?
此外,当我单击关闭按钮时,应用程序崩溃,并显示错误消息“PROGRAM RECEIVED ERROR MESSAGE SIGBRT”。我认为我的两个问题是相关的。有什么帮助吗?
回答by Mundi
Just implement dismissActionSheet
and put your dismiss message there.
只需实施dismissActionSheet
并将您的解雇消息放在那里。
The dismissActionSheet
method would look something like this:
该dismissActionSheet
方法看起来像这样:
-(void)dismissActionSheet {
[sheet dismissWithClickedButtonIndex:0 animated:YES];
}