Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 观察者使用RemoveAllober多次开火_Ios_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Ios 观察者使用RemoveAllober多次开火

Ios 观察者使用RemoveAllober多次开火,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我有一个iAction,当按下它时,它会创建一个观察者侦听器并获取快照数据 当某个子节点更改值时,我希望关闭当前的ViewController并显示不同的ViewController 当ViewController被解除时,我将尝试删除所有观察者句柄 但当我构建和运行时,从我的控制台输出判断,我的Firebase观察器似乎因为未知的原因被多次调用 This is being executed in the observer This is being executed in the observ

我有一个iAction,当按下它时,它会创建一个观察者侦听器并获取快照数据

当某个子节点更改值时,我希望关闭当前的ViewController并显示不同的ViewController

当ViewController被解除时,我将尝试删除所有观察者句柄

但当我构建和运行时,从我的控制台输出判断,我的Firebase观察器似乎因为未知的原因被多次调用

This is being executed in the observer
This is being executed in the observer
This is being executed in the observer
This is being executed in the observer
This is being executed in the observer
This is being executed in the observer
2016-07-25 14:03:06.125 SSM[636:140771] Warning: Attempt to present <SSM.activeViewController: 0x13eb3b200> on <SSM.userProfileViewController: 0x13f18c400> while a presentation is in progress!
2016-07-25 14:03:06.125 SSM[636:140771] Warning: Attempt to dismiss from view controller <UINavigationController: 0x13f24ba00> while a presentation or dismiss is in progress!
2016-07-25 14:03:06.125 SSM[636:140771] Warning: Attempt to present <SSM.activeViewController: 0x13eb3b200> on <SSM.userProfileViewController: 0x13f18c400> while a presentation is in progress!
2016-07-25 14:03:06.125 SSM[636:140771] Warning: Attempt to dismiss from view controller <UINavigationController: 0x13f24ba00> while a presentation or dismiss is in progress!
2016-07-25 14:03:06.125 SSM[636:140771] Warning: Attempt to present <SSM.activeViewController: 0x13eb3b200> on <SSM.userProfileViewController: 0x13f18c400> while a presentation is in progress!
2016-07-25 14:03:06.125 SSM[636:140771] Warning: Attempt to dismiss from view controller <UINavigationController: 0x13f24ba00> while a presentation or dismiss is in progress!

您可以使用observeSingleEventOfType(.Value,with block:,这样就不必删除observeSingleEventOfType


此外,正如@Shubhank所指出的,您必须在您撤销的viewcontroller中显示VC。由于您撤销了它,因此self不能有效地显示,这就是为什么警告可以使用
observeSingleEventOfType(.Value,with block:
,因此您不必删除observer


此外,正如@Shubhank所指出的,您必须在您驳回的viewcontroller中呈现VC。由于您驳回了自我,因此自我无法有效呈现,这就是为什么警告必须在您驳回的viewcontroller中呈现VC。由于您驳回了自我,因此自我无法有效呈现,这就是警告的原因ng@Shubhank想把它写下来作为答案吗?你必须在你驳回的viewcontroller中展示VC。自我是无效的,因为你驳回了它,这就是为什么warning@Shubhank想写下来作为答案吗?
  self.rootRef.child("users/").child(NSUserDefaults.standardUserDefaults().stringForKey("id")!).observeEventType(.Value, withBlock: { snapshot in
        if (snapshot.value!.objectForKey("otherUserID") as? String)! != "" {

            print("This is being executed in the 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()
}