从PFLogInViewController中查看

时间:2015-02-09 21:24:57

标签: swift parse-platform

我尝试使用PFLogInViewController()成功登录后使用解析来尝试转换到另一个视图控制器,但它不能正常工作。代码发布在下面。 PFLogInViewController只是不断弹出和解雇。

class ViewController: UIViewController, PFLogInViewControllerDelegate {

    override func viewDidAppear(animated: Bool) {

        var logInController = PFLogInViewController()
        logInController.fields = (PFLogInFields.UsernameAndPassword
            | PFLogInFields.LogInButton
            | PFLogInFields.SignUpButton
            | PFLogInFields.PasswordForgotten
            | PFLogInFields.DismissButton)


        logInController.delegate = self
        self.presentViewController(logInController, animated: true, completion: nil)



        PFUser.logInWithUsernameInBackground("tester1", password: "test123"){
            (user: PFUser!, error: NSError!) -> Void in
            if user != nil {
                self.dismissViewControllerAnimated(true, completion: nil)
                self.presentViewController(picsViewController(), animated: true, completion: nil)
            }
        }



    }

3 个答案:

答案 0 :(得分:0)

是的,您正在viewDidAppear中重新创建它。当前一个视图完成时,是否正在调用viewDidAppear?您可能希望将其移动到仅调用一次的viewDidLoad。

答案 1 :(得分:0)

[PFUser logInWithUsernameInBackground:_username.text password:_password.text block:^(PFUser *user, NSError *error) {
    if (!error) {
        [self performSegueWithIdentifier:@"YOURSEGUEIDENTIFIER" sender:self];

    }

    if (error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login Error" message:@"There was an error login you in. Please check username and password and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }

}];

}

答案 2 :(得分:0)

不太确定它是否能解决所有问题,但一个好的起点就是添加

     super.viewDidAppear(animated) 

这可能会阻止它开启和关闭

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
}

在该控制器上的所有代码之上