如何使用关闭按钮关闭 UIActionSheet 并避免崩溃?

发布于 2024-12-19 14:46:00 字数 1856 浏览 3 评论 0原文

我读过另一篇文章(如何解除操作表),我可以用

[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]; 

此外,当我单击关闭按钮时,应用程序崩溃,并显示错误消息“程序收到错误”消息 SIGBRT”。我认为我的两个问题是相关的。有什么帮助吗?

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 *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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天邊彩虹 2024-12-26 14:46:00

只需实现 dismissActionSheet 并将您的解雇消息放在那里即可。

dismissActionSheet 方法看起来像这样:

-(void)dismissActionSheet {
   [sheet dismissWithClickedButtonIndex:0 animated:YES];
}

Just implement dismissActionSheet and put your dismiss message there.

The dismissActionSheet method would look something like this:

-(void)dismissActionSheet {
   [sheet dismissWithClickedButtonIndex:0 animated:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文