【问题标题】:UIActionSheet presented using Popover causing issues使用 Popover 呈现的 UIActionSheet 导致问题
【发布时间】: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];
}

这两个类中没有其他代码。我不知道为什么会这样,实际上它发生在我的一个客户项目中,所以我用上面的代码创建了一个测试应用程序,它也导致了这个问题。

屏幕截图

我尝试过的:

  1. 我检查了UIAlertController Class Reference
  2. 在 Google 上进行了搜索,没有任何结果

替代方案:

  1. 如果我将 Second class 设置为我的 rootViewController,则问题不会存在(但我不能这样做,我需要来回导航)
  2. 如果我在外面触摸时禁用弹出框关闭,它可以避免这个问题。但我需要这个工作流程。

有人可以帮帮我吗?我现在完全迷路了,没有得到任何有用的信息。 提前致谢。

【问题讨论】:

  • 对我来说,这听起来像是视图控制器堆栈中的一个错误,您是否尝试过更改 secondVC 的呈现方式,使其位于 UINavigationController 中?
  • @Jef:我不这么认为。这是一个单视图应用程序(添加了一个额外的 vc,添加了上面提到的代码)仅此而已。

标签: ios objective-c ipad uipopovercontroller uialertcontroller


【解决方案1】:

我不知道是什么问题,但我已经解决了。我使用了popoverPresentationControllerShouldDismissPopover 并返回了YES

- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;
{
    return YES;
}

尤里卡:

这是个意外!!!我没有任何其他方法来解决这个问题,所以我想会做第二种选择。在写作时,我不小心写了YES 而不是NO。但它起作用了,我不知道它是如何起作用的,以及导致该问题的原因是什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-27
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多