iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – 如何使用关闭按钮关闭UIActionSheet并避免崩溃?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我已阅读另一篇文章( how to dismiss action sheet),我可以使用 [actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 使用关闭按钮关闭uiactionsheet,如下所述: UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithtitle:
我已阅读另一篇文章( how to dismiss action sheet),我可以使用

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

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,320,485)];

但是,我不知道在哪里放置这一行,假设这将解决我的问题:

[actionSheet dismissWithClickedButtonIndex:0 animated:YES];

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

解决方法

只需实现dismissActionSheet并将你的dismiss消息放在那里.

dismissActionSheet方法看起来像这样

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

大佬总结

以上是大佬教程为你收集整理的objective-c – 如何使用关闭按钮关闭UIActionSheet并避免崩溃?全部内容,希望文章能够帮你解决objective-c – 如何使用关闭按钮关闭UIActionSheet并避免崩溃?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。