gpt4 book ai didi

swift - 自定义 UIAlertController - 应用程序尝试以模态方式呈现事件 Controller

转载 作者:搜寻专家 更新时间:2023-10-31 22:57:31 24 4
gpt4 key购买 nike

应用程序试图以模态方式呈现事件 Controller

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

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller

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)

}
}

问题出在哪里?谢谢

最佳答案

您正试图在您的 show 方法中显示错误的 Controller 。

改变:

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

到:

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

关于swift - 自定义 UIAlertController - 应用程序尝试以模态方式呈现事件 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43280457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com