gpt4 book ai didi

ios - 在 swift iOS 中管理用户登录 segues

转载 作者:行者123 更新时间:2023-11-28 13:12:15 25 4
gpt4 key购买 nike

我正在尝试为 iPhone 应用程序构建初始用户登录系统。我创建了一个包含所有用户数据的 API。我已经成功地建立了从我的 swift 代码到我的 API 的 HTTP 连接,我在其中向用户发送登录详细信息,API 对用户进行身份验证并将用户数据作为 JSON 发送。

我的 Storyboard中有 2 个 View ,如下所示:

enter image description here

我想控制 segue 转换,所以它只会在用户成功通过身份验证时转到下一个 View ,否则它会停留在同一 View 上,但会在与 相同的 View 上输出一条消息“错误登录详细信息”。

有什么办法可以实现吗?

如果我在问题中犯了任何错误,我深表歉意。如果您需要更多信息来回答问题,请告诉我。

更新:遇到错误!

在进行下面建议的更新后,我遇到了以下错误。知道如何修复它们。

我的代码:

enter image description here

错误:

enter image description here

最佳答案

我建议您使用以下代码在用户成功登录时启动 View Controller :

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("nextViewController") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)

通过这种方式,您可以轻松地控制导航,如果用户没有输入正确的信息,那么您可以向其他部分显示警报,如下面的代码所示:

dispatch_async(dispatch_get_main_queue()) {

if user successfully logIn {

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("nextViewController") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)


} else {

var alert = UIAlertController(title: "Alert", message: "Please enter correct Information", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

}
}

希望对您有所帮助。

关于ios - 在 swift iOS 中管理用户登录 segues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30885938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com