我有以下代码:

loginViewModel.facebookLogin
.asObservable()
subscribe() { [unowned self] facebookLogin in
     if let isLoggedIn = facebookLogin.element?.isLoggedIn {
         if isLoggedIn {
              elf.performSegue(withIdentifier: "toRestaurantSelect", sender: self)
              }
      }

     if let didLoginFail = facebookLogin.element?.didLoginFail {
         self.errorLabel.isHidden = !didLoginFail
     }
  }
.disposed(by: disposeBag)


facebookLogin是一个变量,并在用户登录时更新。但是,不调用performSegue(条件为true)。奇怪的是,如果我在模拟器中打开慢速动画,则会执行segue。当关闭慢速动画时,将不会执行搜索(Facebook登录有效)。任何帮助表示赞赏。谢谢!

最佳答案

我认为你应该使用主线程来使其工作

    loginViewModel.facebookLogin
        .asObservable()
        .subscribe() { [unowned self] facebookLogin in
            if let isLoggedIn = facebookLogin.element?.isLoggedIn {
                if isLoggedIn {


                    DispatchQueue.main.async {
                        self.performSegue(withIdentifier: "toRestaurantSelect", sender: self)

                    }



                }
            }

            if let didLoginFail = facebookLogin.element?.didLoginFail {
                self.errorLabel.isHidden = !didLoginFail
            }
        }
        .disposed(by: disposeBag)

关于ios - swift-performSegue在RxSwift中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50668925/

10-09 09:13