【问题标题】:Custom UIAlertController - Application tried to present modally an active controller自定义 UIAlertController - 应用程序试图以模态方式呈现活动控制器
【发布时间】:2017-09-02 23:25:39
【问题描述】:

应用程序试图以模态方式呈现一个活动控制器

我正在尝试创建自定义 UIAlertController。 因此,来自不同地方的工作将更容易。 但我收到了这个错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图以模态方式呈现活动控制器

class CustomAlert: UIAlertController,  UIImagePickerControllerDelegate, UINavigationControllerDelegate  {

    private static var sheet : UIAlertController = UIAlertController()
    static let instance = CustomAlert()

    func create(title: String, message: String) -> CustomAlert {
        CustomAlert.sheet = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
        return self
    }

    func addlibrary() -> CustomAlert{
        let libraryAction = UIAlertAction(title: "library", style: .default, handler: nil)
        CustomAlert.sheet.addAction(libraryAction)
        return self
    }

    func show(on vc : UIViewController){
          UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)

    }
}

问题出在哪里? 谢谢

【问题讨论】:

    标签: swift swift3 uialertcontroller


    【解决方案1】:

    您试图在您的 show 方法中显示错误的控制器。

    变化:

    UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
    

    到:

    vc.present(self, animated: true, completion: nil)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 2011-12-25
      • 1970-01-01
      • 2014-03-03
      • 2013-02-15
      • 1970-01-01
      • 2020-06-06
      • 2011-12-16
      相关资源
      最近更新 更多