swift - Warning: Attempt to Present ViewController on whose ViewController isn't in the view hierarchy (3D Touch) -


basically, trying implement home screen quick actions app. when tap on 1 of quick actions error:

warning: attempt present theviewcontroller on viewcontroller view not in window hierarchy!

i have looked @ other stack on flow posts had same issue, solutions didn't work me. also, in applicationdidenterbackground method added self.window?.rootviewcontroller?.dismissviewcontrolleranimated(true, completion: nil).

here of relevant 3d touch methods have included in app delegate:

func application(application: uiapplication, performactionforshortcutitem shortcutitem: uiapplicationshortcutitem, completionhandler: (bool) -> void) {     let handledshortcutitem = self.handleshortuctitem(shortcutitem)     completionhandler(handledshortcutitem) } 

also, have these helper methods:

    enum shortcutidentifier: string {     case first     case second      init?(fulltype: string) {         guard let last = fulltype.componentsseparatedbystring(".").last else { return nil }         self.init(rawvalue: last)     }     var type: string {         return nsbundle.mainbundle().bundleidentifier! + ".\(self.rawvalue)"     } }  func handleshortuctitem(shortcutitem: uiapplicationshortcutitem) -> bool {     var handled = false      guard shortcutidentifier(fulltype: shortcutitem.type) != nil else { return false }     guard let shortcuttype = shortcutitem.type string? else { return false }      switch(shortcuttype) {     case shortcutidentifier.first.type:         handled = true         let navvc = mainstoryboard.instantiateviewcontrollerwithidentifier("firstviewcontroller") as! firstviewcontroller         self.window?.rootviewcontroller?.presentviewcontroller(navvc, animated: true, completion: nil)         break     case shortcutidentifier.second.type:         handled = true         let navvc = mainstoryboard.instantiateviewcontrollerwithidentifier("secondviewcontroller") as! secondviewcontroller         self.window?.rootviewcontroller?.presentviewcontroller(navvc, animated: true, completion: nil)         break     default:         break     }       return handled } 

a sort of mindless solution wrap delay around presentviewcontroller calls (delay defined here: dispatch_after - gcd in swift?):

switch(shortcuttype) { case shortcutidentifier.first.type:     handled = true     let navvc = mainstoryboard.instantiateviewcontrollerwithidentifier("firstviewcontroller") as! firstviewcontroller     delay(0.3) {         self.window?.rootviewcontroller?.presentviewcontroller(navvc, animated: true, completion: nil)     }     break case shortcutidentifier.second.type:     handled = true     let navvc = mainstoryboard.instantiateviewcontrollerwithidentifier("secondviewcontroller") as! secondviewcontroller     delay(0.3) {         self.window?.rootviewcontroller?.presentviewcontroller(navvc, animated: true, completion: nil)     }     break default:     break } 

the idea give interface time finish appearing before trying presentation.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -