【问题标题】:Unable to dismissViewControllerAnimated iOS 9.3无法关闭ViewControllerAnimated iOS 9.3
【发布时间】:2016-04-02 09:06:46
【问题描述】:

我正在显示 UIAlertControllerUIAlertAction 我正在关闭视图控制器。它在 iOS 9.3 之前运行良好。但在 iOS 9.3 中它不起作用。以下是代码。

let alertController = UIAlertController(title: "Logged In Successfully", message: "asda", preferredStyle: .Alert)

 // Create the actions
    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { UIAlertAction in
                            self.dismissViewControllerAnimated(true, completion: nil)
                        }

                        // Add the actions
                        alertController.addAction(okAction)

                        // Present the controller
                        self.presentViewController(alertController, animated: true, completion: nil)

【问题讨论】:

    标签: swift2 uialertcontroller ios9.3


    【解决方案1】:

    尝试在dismissViewControllerAnimated 行中设置断点,并在按下OK 时检查它是否到达那里。

    如果不是 - 尝试替换

    UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { UIAlertAction in
                                self.dismissViewControllerAnimated(true, completion: nil)
                            }
    

    用这个:

    UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { _ in
                                self.dismissViewControllerAnimated(true, completion: nil)
                            } 
    

    【讨论】:

    • 我添加了断点。 Alertcontroller 正在工作,但 dismissViewController 没有执行。
    • 您是否尝试将 UIAlertAction 参数替换为 _ ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 2016-11-01
    • 2015-11-25
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多