【问题标题】:Segue is not being performed未执行 Segue
【发布时间】:2020-02-29 02:28:20
【问题描述】:

我创建了一个通过 Firebase 自动登录的方法,但不知何故我的 segue 没有被执行..

我有这段代码,在我的 viewDidLoad 中我正在调用方法 (ofc)

override func viewDidLoad() {
super.viewDidLoad()

  //Login user automatically
  autoLogin()
}

func autoLogin(){
    if Auth.auth().currentUser?.email != nil{

        print("not nil") //for test
        self.performSegue(withIdentifier: "toRootVc", sender: self)
        print("not nil1") //for test
    }
    else{
        print("nil") //for test
    }
}

应用程序同时打印“not nil”和“not nil1”,但仍然没有 执行转场。

我还有一个可用的登录按钮。

func handleLogin(){
    Auth.auth().signIn(withEmail: email.text!, password: password.text!) { (result, err) in
        if let err = err{
            print("Error logging in:", err.localizedDescription)
        }
        else{
            self.databaseHandler.retrieveData(email: self.email.text!){
                self.performSegue(withIdentifier: "toRootVc", sender: self)
            }
        }
    }
}

但 autoLogin 实际上并没有执行 segue。 (忽略步骤)

任何意见将不胜感激。

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    Segues 不能在 viewDidLoad 中工作,因为现在尝试在 viewWillAppear 中还为时过早,或者最好在展示 didFinishLaunchingWithOptionsAppDelegate 中的 vc 之前进行此检查

    【讨论】:

    • 我不能在 didFinishLaunching 中执行 segue 对吗?
    • 没有segue,您可以创建目标vc的实例并将其分配给window?.rootViewController
    • 哦,有道理。那么,加载速度会更快,对吧?
    • 您有任何更具体的 AppDelegate 示例吗?
    • 我得到:“'AppDelegate' 类型的值没有成员 'window'”
    【解决方案2】:

    你有没有试过把这个 autoLogin() 放在 viewDidAppear() 上

    【讨论】:

    • viewDidAppear 是一个不好的地方,因为登录 vc 会出现一段时间
    • 确实有效。但正如@Sh_Khan 所说,登录 vc 确实出现了一毫秒。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 2017-12-06
    • 2018-11-08
    • 1970-01-01
    相关资源
    最近更新 更多