【发布时间】:2015-03-10 21:09:08
【问题描述】:
问题
我遇到了UIAlertController 的问题。这是一个 iPad 项目,因为我有两个类,分别是 First 和 Second。
我正在使用模态演示来演示 Second from First。在 Second Class 中,我有一个按钮,单击它我正在显示 UIActionSheet 以执行一些操作。它工作得很好,除非用户快速单击按钮,否则第二类将被关闭。
代码
第一个 VC:
- (IBAction)showNext:(id)sender
{
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondVC"];
[self presentViewController:vc animated:YES completion:nil];
}
第二个 VC:
- (IBAction)showActionSheet:(UIButton *)sender
{
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
[alertVC addAction:[UIAlertAction actionWithTitle:@"LogOut"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action)
{
}]];
[alertVC addAction:[UIAlertAction actionWithTitle:@"Update"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
}]];
[alertVC setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alertVC popoverPresentationController];
popPresenter.sourceView = sender;
popPresenter.sourceRect = sender.bounds;
[self presentViewController:alertVC animated:YES completion:nil];
}
这两个类中没有其他代码。我不知道为什么会这样,实际上它发生在我的一个客户项目中,所以我用上面的代码创建了一个测试应用程序,它也导致了这个问题。
屏幕截图
我尝试过的:
- 我检查了UIAlertController Class Reference
- 在 Google 上进行了搜索,没有任何结果
替代方案:
- 如果我将 Second class 设置为我的
rootViewController,则问题不会存在(但我不能这样做,我需要来回导航) - 如果我在外面触摸时禁用弹出框关闭,它可以避免这个问题。但我需要这个工作流程。
有人可以帮帮我吗?我现在完全迷路了,没有得到任何有用的信息。 提前致谢。
【问题讨论】:
-
对我来说,这听起来像是视图控制器堆栈中的一个错误,您是否尝试过更改 secondVC 的呈现方式,使其位于 UINavigationController 中?
-
@Jef:我不这么认为。这是一个单视图应用程序(添加了一个额外的 vc,添加了上面提到的代码)仅此而已。
标签: ios objective-c ipad uipopovercontroller uialertcontroller