Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录警报swift 2.0后打开新的视图控制器_Swift_Login_Pushviewcontroller - Fatal编程技术网

登录警报swift 2.0后打开新的视图控制器

登录警报swift 2.0后打开新的视图控制器,swift,login,pushviewcontroller,Swift,Login,Pushviewcontroller,如果登录成功,我将尝试更改视图控制器,但我不确定如何执行此操作。这就是我迄今为止所尝试的。提前谢谢 @IBAction func signinaction(sender: AnyObject) { let user = self.usernamefield.text! ref.authUser(emailfield.text, password: passwordfield.text, withCompletionBlock: { error, authData in

如果登录成功,我将尝试更改视图控制器,但我不确定如何执行此操作。这就是我迄今为止所尝试的。提前谢谢

@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)

        }

    })
}

假设所有这些都包含在一个导航控制器中的视图控制器中,您所拥有的应该可以正常工作。但是请注意,您正在创建一个从未显示的警报。我猜您希望显示成功警报,然后打开新的视图控制器,如:

            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)

如果这仍然不起作用,我会确保当前的视图控制器实际显示在导航控制器中。

假设所有这些都包含在导航控制器中的视图控制器中,您所拥有的应该可以正常工作。但是请注意,您正在创建一个从未显示的警报。我猜您希望显示成功警报,然后打开新的视图控制器,如:

            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)

如果这仍然不起作用,我会确保当前视图控制器实际显示在导航控制器中。

看起来您只需要在警报操作中添加导航代码。当前,处理程序参数设置为nil

这个

变成这样

 let alertAction = UIAlertAction(title: "Ok", style: .Default) { (action) -> Void in
        self.navigationController?.pushViewController(vc as HomeViewController, animated: true)

    }

看起来您只需要在警报操作中添加导航代码。当前,处理程序参数设置为nil

这个

变成这样

 let alertAction = UIAlertAction(title: "Ok", style: .Default) { (action) -> Void in
        self.navigationController?.pushViewController(vc as HomeViewController, animated: true)

    }