UIAlertView Unwind Segue Handler



我有一个模态呈现的视图控制器,我想放松一下。我已经设置了,如果我按"取消",它将执行一个展开 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];
    }
}

通过选择整个视图控制器并按住 ctrl 拖动鼠标退出,从情节提要中声明手动展开序列。为该 segue 提供一个标识符,并使用 performSegueWithIdentifier 方法从 UIAlertView 的委托触发该 segue

最新更新