加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 在ViewDidLoad中执行Segue [复制]

发布时间:2020-12-14 18:59:39 所属栏目:百科 来源:网络整理
导读:参见英文答案 Perform Segue on ViewDidLoad????????????????????????????????????12个 我试图在第一次加载应用程序时执行segue. 我可以在调试器中看到我的打印消息,但Perform Segue不起作用.我没有得到任何错误. 有人可以告诉我什么错了吗? import UIKitim
参见英文答案 > Perform Segue on ViewDidLoad????????????????????????????????????12个
我试图在第一次加载应用程序时执行segue.
我可以在调试器中看到我的打印消息,但Perform Segue不起作用.我没有得到任何错误.
有人可以告诉我什么错了吗?

import UIKit
import LocalAuthentication
let isFirstLaunch = UserDefaults.isFirstLaunch()
extension UserDefaults {
    // check for is first launch - only true on first invocation after app install,false on all further invocations
    // Note: Store this value in AppDelegate if you have multiple places where you are checking for this flag
    static func isFirstLaunch() -> Bool {
        let hasBeenLaunchedBeforeFlag = "hasBeenLaunchedBeforeFlag"
        let isFirstLaunch = !UserDefaults.standard.bool(forKey: hasBeenLaunchedBeforeFlag)
        if (isFirstLaunch) {

            UserDefaults.standard.set(true,forKey: hasBeenLaunchedBeforeFlag)
            UserDefaults.standard.synchronize()
        }
        return isFirstLaunch
    }
}

class loginVC: UIViewController {





    override func viewDidLoad() {

        super.viewDidLoad()

        if  isFirstLaunch == false {
          performSegue(withIdentifier: "setPassword",sender: self)
            print("testFalse") }
            else {
            performSegue(withIdentifier: "setPassword",sender: self)
            print("testTrue")}


        //       Do any additional setup after loading the view,typically from a nib.




    }

解决方法

您不能在viewDidLoad()中使用performSegue().将其移至viewDidAppear().

在viewDidLoad()时,当前视图甚至没有附加到窗口,因此不可能进行segue.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读