ios - 在目标 c 中使用 UIAlertViewController 时如何关闭呈现的视图控制器?
问题描述
我没有使用任何使用导航控制器来呈现视图控制器。在该视图控制器中,我使用 NSTimer 在特定时间后关闭视图控制器。我还使用 AlertViewController 来显示时间结束的警报。但在那之后,只有 AlertViewController 不会关闭实际视图控制器。代码如下:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert" message:@"Run Loop" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//button click event
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancel];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
[self stop]; ***************** **Executing this function**
}
在特定时间后执行的功能是:
-(void)stop{
[self dismissViewControllerAnimated:YES completion:nil];
}
当我使用 presentViewController 呈现警报时。因此,如果您使用 self.dismissViewController,它只会关闭警报,而不是父视图控制器。那么如何关闭父视图控制器呢?注意:我没有使用任何导航控制器。
解决方案
A)只需使用代码,我就可以关闭呈现的视图控制器:
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
B) 或者另一种选择可以是首先我们关闭视图控制器,然后在完成处理程序上我们可以呈现 UIAlertViewController。
推荐阅读
- python - lambda函数中python中两个不同事件(sns和emr)之间可能不同的函数
- r - 将具有多个标题的数据重新格式化为长格式,一个标题行成为新列中的数据
- excel - 使用 VBA 循环遍历工作表中的每个打印页面
- c# - 如何修复“没有命名的事件中心接收器
" - excel - 计算 Excel 数据集中的重叠
- aws-fargate - AWS 如何对 Fargate 任务的使用收费?
- php - 如果条件满足,则回显变量
- oracle-apex - 在 Oracle APEX 中管理用户
- powerbi - 如何将计算列添加到将忽略切片器 Power BI 中的选定值的现有表
- python - Endswith 和 Replacement 语法 - Pandas