加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 如何使用关闭按钮关闭UIActionSheet并避免崩溃?

发布时间:2020-12-14 19:45:33 所属栏目:百科 来源:网络整理
导读:我已阅读另一篇文章( how to dismiss action sheet),我可以使用 [actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 使用关闭按钮关闭uiactionsheet,如下所述: UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate
我已阅读另一篇文章( 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];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读