首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >覆盖alertView方法

覆盖alertView方法
EN

Stack Overflow用户
提问于 2015-06-29 14:04:13
回答 1查看 247关注 0票数 0

我有个有扣子的手机。此按钮用于删除单元格,当我单击该按钮时,会在删除之前显示一个alertView。我想要的是将单元格参数传递给方法,如下所示:

代码语言:javascript
复制
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex forCell:(MissionCollectionViewCell *) cell 

但我不知道如何在初始化UIAlertView的过程中做到这一点?

代码语言:javascript
复制
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Etes-vous sûr de vouloir supprimer cette mission ?" delegate:self cancelButtonTitle:@"Supprimer" otherButtonTitles:@"Annuler", nil];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-29 14:40:06

如果您只想支持iOS8+,那么应该使用UIAlertController,它为操作提供了基于块的处理程序,从而方便了对变量的访问。如果像我们中的许多人一样,您需要满足那些没有立即升级的人,我发现描述这里的方法是处理UIAlertView的最佳方法。

该链接中的示例向UIAlertView添加了一个类别,以允许您使用块而不是委托来处理警报视图完成。使用您的示例,可以引发警报,并允许您在完成过程中访问所需的任何变量:

代码语言:javascript
复制
UIAlertView *alert = 
  [[UIAlertView alloc] initWithTitle:@"Attention" 
                             message:@"Etes-vous sûr de vouloir supprimer cette mission ?" 
                            delegate:self 
                   cancelButtonTitle:@"Supprimer" otherButtonTitles:@"Annuler", nil];

[alert showWithCompletion:^(UIAlertView *alertView, NSInteger buttonIndex) {
    // Since this is a block defined where you called it you can use
    // the variables you want directly 8^).
    if (buttonIndex == alertView.cancelButtonIndex){
      ... Code can access cell directly.
    }
}];

我现在一直使用它,因为在您发出警报视图的位置旁边有您的完成代码要简单得多。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31117767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档