ios - Observer Fires Multiple Times with removeAllObervers -


i have ibaction when pressed, creates observer listener , gets snapshot data.

when child node changes value, want dismiss current viewcontroller , present different viewcontroller.

when viewcontroller gets dismissed, attempting remove observer handles.

but when build , run, judging console output, seems firebase observer being called multiple times unknown.

this being executed in observer being executed in observer being executed in observer being executed in observer being executed in observer being executed in observer 2016-07-25 14:03:06.125 ssm[636:140771] warning: attempt present <ssm.activeviewcontroller: 0x13eb3b200> on <ssm.userprofileviewcontroller: 0x13f18c400> while presentation in progress! 2016-07-25 14:03:06.125 ssm[636:140771] warning: attempt dismiss view controller <uinavigationcontroller: 0x13f24ba00> while presentation or dismiss in progress! 2016-07-25 14:03:06.125 ssm[636:140771] warning: attempt present <ssm.activeviewcontroller: 0x13eb3b200> on <ssm.userprofileviewcontroller: 0x13f18c400> while presentation in progress! 2016-07-25 14:03:06.125 ssm[636:140771] warning: attempt dismiss view controller <uinavigationcontroller: 0x13f24ba00> while presentation or dismiss in progress! 2016-07-25 14:03:06.125 ssm[636:140771] warning: attempt present <ssm.activeviewcontroller: 0x13eb3b200> on <ssm.userprofileviewcontroller: 0x13f18c400> while presentation in progress! 2016-07-25 14:03:06.125 ssm[636:140771] warning: attempt dismiss view controller <uinavigationcontroller: 0x13f24ba00> while presentation or dismiss in progress! 

snippet ibaction

  self.rootref.child("users/").child(nsuserdefaults.standarduserdefaults().stringforkey("id")!).observeeventtype(.value, withblock: { snapshot in         if (snapshot.value!.objectforkey("otheruserid") as? string)! != "" {              print("this being executed in observer")              self.dismissviewcontrolleranimated(false, completion: nil)              let storyboard = uistoryboard(name: "main", bundle: nil)             let controller = storyboard.instantiateviewcontrollerwithidentifier("active")             self.presentviewcontroller(controller, animated: true, completion: nil)         }     })   override func viewdiddisappear(animated: bool) {     self.rootref.child(nsuserdefaults.standarduserdefaults().stringforkey("id")!).removeallobservers() } 

you can use observesingleeventoftype(.value, withblock:, don't have remove observer

also, @shubhank pointed, have present vc in viewcontroller dismissed to. self isn't valid present since have dismissed , that's why warning


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 -