ios - UIAlertView 展开 Segue 处理程序

标签 ios objective-c uialertview segue

我有一个模态呈现的 View Controller ,我想展开它。我已将其设置为如果我按“取消”,它将执行一个 unwind segue。但是,我想使用 UIAlertView 制作一个确认按钮。如“您确定要取消吗?”。我如何使用 UIAlertView 按钮触发展开转场?

最佳答案

在您的 .h 文件中,声明 UIAlertViewDelegate。然后在你的 .m 文件中,你可以在取消按钮操作方法中编写代码:

- (IBAction)confirmationButtonPressed:(id)sender{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Are you sure you'd like to cancel?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
    [alert show];
}

然后你可以在你的 .m 文件中添加 UIAlertView Delegate 方法:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 0){
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

关于ios - UIAlertView 展开 Segue 处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28080315/

相关文章:

iphone - Interface Builder 对象库中缺少对象

Objective-c,将 NSURLConnection 结果传递给 View Controller

ios - 启用位码是否适用于 iOS 9(iOS 7/8)之前的 iOS 版本?

ios - 在应用程序运行时在 AppDelegate 中运行 didFinshLaunchingWithOptions?

android - 从iOS Swift代码显示FlutterView时出现问题

ios - 当 View Controller 在顶部时调用函数

ios - 如何根据 UITextField 禁用 UIAlertAction?

ios - UIDatePicker 最小和最大日期不变

IOS 8 无法从 UITextField 中关闭键盘

ios - 检测来自另一个 VC 的警报是否可见