我有个有扣子的手机。此按钮用于删除单元格,当我单击该按钮时,会在删除之前显示一个alertView。我想要的是将单元格参数传递给方法,如下所示:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex forCell:(MissionCollectionViewCell *) cell 但我不知道如何在初始化UIAlertView的过程中做到这一点?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Etes-vous sûr de vouloir supprimer cette mission ?" delegate:self cancelButtonTitle:@"Supprimer" otherButtonTitles:@"Annuler", nil];发布于 2015-06-29 14:40:06
如果您只想支持iOS8+,那么应该使用UIAlertController,它为操作提供了基于块的处理程序,从而方便了对变量的访问。如果像我们中的许多人一样,您需要满足那些没有立即升级的人,我发现描述这里的方法是处理UIAlertView的最佳方法。
该链接中的示例向UIAlertView添加了一个类别,以允许您使用块而不是委托来处理警报视图完成。使用您的示例,可以引发警报,并允许您在完成过程中访问所需的任何变量:
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.
}
}];我现在一直使用它,因为在您发出警报视图的位置旁边有您的完成代码要简单得多。
https://stackoverflow.com/questions/31117767
复制相似问题