登录后如何将登录屏幕与主屏幕连接?

问题描述 投票:0回答:1

我有一个登录屏幕,并希望在登录后将其连接到我的主页。我创建了带有标识符的Segue,但尝试时不起作用。我该怎么办?

                   let message = json!["message"] as? String


                   if (message?.contains("success"))!{


                  self.performSegue(withIdentifier: "homelogin", sender: self)


                       let id = json!["id"] as? String
                       let name = json!["name"] as? String
                       let username = json!["username"] as? String
                       let email = json!["email"] as? String



                       print(String("Emri") + name! )
                       print(String("Emaili") + email! )
                       print(String("Id") + id! )
                       print(String("username") + username! )


                   }else{
                       print(String("check your password or email"))
                   }

                [enter image description here][1]

这是带标识符的标记

ios swift swift3
1个回答
0
投票

您的代码有很多问题。试试看,让我知道它是否有效。我还为所做的更改添加了解释。

if let json = json { // The “if let” allows us to unwrap optional values safely only when there is a value, and if not, the code block will not run and jump to else statement

    let message = json["message"] as? String ?? "" // The nil-coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil. 

    if message == "success" {
        self.performSegue(withIdentifier: "homelogin", sender: self)


        let id = json["id"] as? String ?? "" // String can directly be entered in double quotes. no need to use String()

        let name = json["name"] as? String ?? ""
        let username = json["username"] as? String ?? ""
        let email = json["email"] as? String ?? ""



        print("Emri " + name )
        print("Emaili " + email )
        print("Id " + id )
        print("username " + username )


    }else{
        print("check your password or email")
    }
} else {
    print("Invalid json")
}
© www.soinside.com 2019 - 2024. All rights reserved.