gpt4 book ai didi

swift - 登录警报 swift 2.0 后打开一个新的 View Controller

转载 作者:行者123 更新时间:2023-11-28 08:42:52 25 4
gpt4 key购买 nike

如果登录成功,我正在尝试更改 View Controller ,但我不确定如何执行此操作。到目前为止,这是我尝试过的。提前致谢!

@IBAction func signinaction(sender: AnyObject) {
let user = self.usernamefield.text!

ref.authUser(emailfield.text, password: passwordfield.text, withCompletionBlock: { error, authData in

if error != nil
{
let alert = UIAlertController(title: "Error", message: "Enter Email and Password.", preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "Ok", style: .Default, handler: nil)
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
print("can not sign in")
}
else
{

let storyboard = UIStoryboard(name: "Main", bundle: nil);
let viewName:NSString = "NewView"
let vc = storyboard.instantiateViewControllerWithIdentifier(viewName as String) as! HomeViewController
let uid = authData.uid
print("Success with user: \(uid)")
let alert = UIAlertController(title: "Success", message: "Welcome \(user)", preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "Ok", style: .Default, handler: nil)
alert.addAction(action)
self.navigationController?.pushViewController(vc as HomeViewController, animated: true)

}

})
}

最佳答案

假设所有这些都包含在导航 Controller 中的 View Controller ,那么您所拥有的应该可以正常工作。但是请注意,您正在创建一个永远不会显示的警报。我的猜测是您想显示成功警报,然后打开新的 View Controller ,例如:

            let alert = UIAlertController(title: "Success", message: "Welcome \(user)", preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "Ok", style: .Default) { _ in
self.navigationController?.pushViewController(vc, animated: true)
}
alert.addAction(action)

self.presentViewController(alert, animated: true, completion: nil)

如果这仍然不起作用,我会确保当前 View Controller 实际显示在导航 Controller 中。

关于swift - 登录警报 swift 2.0 后打开一个新的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35999167/

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