简体   繁体   English

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

[英]How do I connect my login screen with my home screen after I login?

I have a login screen and wanted to connect it with my home page after I log in. I created a Segue with Identifier but It doesn't work when I try it.我有一个登录屏幕,并希望在登录后将其与我的主页连接起来。我创建了一个带有标识符的 Segue,但是当我尝试它时它不起作用。 What can I do?我能做些什么?

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"))
}

this is the segue with Identifier这是标识符的转场

There are lots of issues with your code.你的代码有很多问题。 Try it and let me know if it works.试试看,让我知道它是否有效。 I have also added explanation for the changes I done.我还为我所做的更改添加了解释。

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" {
        DispatchQueue.main.async {
            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")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将登录屏幕连接到特定的网站和数据库以接受用户名和密码? - How do I connect my login screen to a specific website & database to accept usernames and passwords? 如何将我的标签栏图标连接到我的屏幕? - How do I connect my tab bar icon to my screen? "如何修复我的代码并让登录屏幕页面上的所有登录按钮正常工作" - How can i fix my code and let all the login button on the login screen page work 如何更改iOS设备主屏幕上应用图标下方显示的名称? - How do I change the name displayed underneath my app icon on my device's Home screen in iOS? 如何在我的TabViewController之前添加登录屏幕 - How to Add a Login Screen Before my TabViewController 如何在Safari中打开来自iOS主屏幕PWA的第三方登录流程? - How do I stop 3rd-party login flow from an iOS home screen PWA from opening in Safari? 如何使用iOS / Swift中的startPasswordAuthentication委托切换到登录屏幕,以便基于Cognito用户池登录? - How do I switch to login screen with the startPasswordAuthentication delegate in iOS/Swift for Cognito User Pools based login? 添加到主屏幕后,我该怎么做才能阻止iPhone 4切断我的标题? - What can I do to prevent iPhone 4 from cutting off my title when adding to home screen? Facebook:当我返回我的应用程序时,登录和权限屏幕没有关闭 - Facebook: login and permission screen does not close when I return to my app 为我的 iPhone 应用程序制作登录屏幕 - Making a login screen for my iphone app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM