ios - Attempt to present UIAlertController on UITabBarController whose view is not in the window hierarchy -


i have timer in app delegate, user choose time interval needed execute selector of timer in viewcontroller not in tab bar; after choosing time interval modal segue used load first viewcontroller in uitabbarcontroller

when time interval passes want app present alert gives me this: warning: attempt present uialertcontroller on uitabbarcontroller view not in window hierarchy!

here code i'am using :

let alert = uialertcontroller(title: "alert", message: "test", preferredstyle: .alert) self.window?.rootviewcontroller?.presentviewcontroller(alert, animated: true, completion: nil) 

first try visible view controller. can this public extension:

 public extension uiwindow {     public var visibleviewcontroller: uiviewcontroller? {         return uiwindow.getvisibleviewcontrollerfrom(self.rootviewcontroller)     }      public static func getvisibleviewcontrollerfrom(vc: uiviewcontroller?) -> uiviewcontroller? {         if let nc = vc as? uinavigationcontroller {             return uiwindow.getvisibleviewcontrollerfrom(nc.visibleviewcontroller)         } else if let tc = vc as? uitabbarcontroller {             return uiwindow.getvisibleviewcontrollerfrom(tc.selectedviewcontroller)         } else {             if let pvc = vc?.presentedviewcontroller {                 return uiwindow.getvisibleviewcontrollerfrom(pvc)             } else {                 return vc             }         }     } } 

and show alert controller in vc


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -