swift - Custom UIAlertController - Application tried to present modally an active controller -


application tried present modally active controller

i'm trying create custom uialertcontroller. different places easier work with. i'm getting error :

terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'application tried present modally 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)      } } 

where problem? thanks

you trying present wrong controller in show method.

change:

uiapplication.shared.keywindow?.rootviewcontroller?.present(vc, animated: true, completion: nil) 

to:

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

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -