2015-05-04 55 views
2

我正在寫一個解析應用程序,並使用解析LoginViewController和SignUpViewController。我一直使用SubclassConfigViewController作爲他們的LoginAndSignUp演示模型。當他們在他們的文檔中討論時,我想在signUp開始之前檢查各種事情的用戶名和密碼。這應該發生在委託函數「signUpViewControllerShouldSignBeginSignUp」
但是,它沒有被調用,並且該應用程序簽署了任何人。它僅檢查電子郵件中的格式是否有效,並且存在用戶名。我在函數的開頭放了一個println(Swift)。它從不打印。 我能做些什麼來強制這個功能運行? 「loginViewControllerShouldLogInUser」按預期運行。解析SignUpViewController signUpViewControllerShouldSignBeginSignUp委託函數沒有被調用

這裏是我的代碼:

class LoginConfigViewController: UIViewController, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate 
{ 

    var loginViewController: LoginViewController! = LoginViewController() 
    var signUpViewController: SignUpViewController! = SignUpViewController() 

    override func viewWillAppear(animated: Bool) 
    { 

     if (PFUser.currentUser() == nil) 
     { 

      loginViewController.delegate = self 
      loginViewController.fields = PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton | PFLogInFields.SignUpButton | PFLogInFields.DismissButton 

      //signUpViewController.delegate = self; 
      signUpViewController.fields = PFSignUpFields.Default | PFSignUpFields.Additional | PFSignUpFields.DismissButton 
      loginViewController.signUpController = signUpViewController; 
      loginViewController.signUpController?.delegate = self 

      self.presentViewController(self.loginViewController, animated: false, completion: nil) 
     } 
     else 
     { 
      self.dismissViewControllerAnimated(false, completion: nil) 
     } 

    } 

    // MARK: - PFLogInViewControllerDelegate 


    func logInViewController(logInController: PFLogInViewController!, shouldLogInUser user: PFUser!, password: String!) -> Bool { 
     println("shouldLogIn...") 

     return true 
    } 

    func logInViewController(logInController: PFLogInViewController, shouldBeginLogInWithUsername username: String, password: String) -> Bool { 
     println("should login in \(username)") 

     return true 
    } 

    @IBAction func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) { 
     println("didLogInUser \(user.username)") 
     self.loginViewController.dismissViewControllerAnimated(false, completion: nil) 

    } 

    // Sent to the delegate when the log in screen is dismissed. 
    func logInViewControllerDidCancelLogin(logInController: PFLogInViewController!) { 
     println("User dismissed the logInViewController") 
     self.loginViewController.dismissViewControllerAnimated(false, completion: nil) 
    } 



    // MARK: - PFSignUpViewControllerDelegate 

    // Sent to the delegate to determine whether the sign up request should be submitted to the server. 
    func signUpViewControllerShouldBeginSignUp(signUpViewController: PFSignUpViewController!, info: NSDictionary) -> Bool { 
     println("signUpViewController::shouldBeginSignUp") 

     return true 
    } 

    // Sent to the delegate when a PFUser is signed up. 
    func signUpViewController(signUpViewController: PFSignUpViewController, didSignUpUser user: PFUser) { 
     println("didSignUpUser \(user.username)") 
     user.removeObjectForKey("additional") 
     self.signUpViewController.stopAI() 
     self.signUpViewController.dismissViewControllerAnimated(false, completion: nil) 
     self.loginViewController.dismissViewControllerAnimated(false, completion: nil) 


    } 


    // Sent to the delegate when the sign up attempt fails. 
    func signUpViewController(signUpViewController: PFSignUpViewController!, didFailtoSignUpWithError error: NSError) { 
     println("Failed to sign up...") 
    } 

    // Sent to the delegate when the sign up screen is dismissed. 
    func signUpViewControllerDidCancelSignUp(signUpViewController: PFSignUpViewController) { 
     println("User dismissed the signUpViewController") 
     signUpViewController.dismissViewControllerAnimated(false, completion: nil) 
    } 

    //MARK: -() 
    func logOutButtonTapAction(sender: AnyObject) { 
     PFUser.logOut() 
     self.dismissViewControllerAnimated(false, completion: nil) 
    } 

} 

回答

0

的LoginController中有一個被稱爲signUpController這是由LoginController中稱爲signupcontroller屬性。

所以,如果你想檢查什麼用戶都(註冊或取消或某事),你需要通過調用此功能來設置的LoginController的signupcontroller的代表:

loginViewController.signUpController?.delegate = self 

希望這有助於

+0

謝謝你的提示。我現在確定了。我毫不懷疑它需要它。但是,「shouldBeginSignUp」函數仍未被調用。謝謝你的幫助。 – epaus

+0

除了添加:「loginViewController.signUpController?.delegate = self」我刪除了:「signUpViewController.delegate = self」但這仍然沒有幫助。 shouldBeginSignUp仍然沒有被調用。 – epaus

+0

@epaus你可以給我你的新代碼(編輯你的問題)? 在我測試的例子上,這工作 – siegy22

0

我有完全相同的問題,默認的解析登錄和註冊控制器不會對他們指定的方法起作用。經過數小時和數小時的問題解決,無法找到答案,結束了不使用默認解析UI和創建我自己的,它工作得很好,談到解析就好了。這是Youtube Video,它向您顯示您需要用於自定義登錄的代碼。出於某種原因,他們的方法只是不會打電話和令人沮喪。一旦用戶登錄,我只用了一個segue到我的主視圖控制器。

self.actInd.startAnimating() 
    PFUser.logInWithUsernameInBackground(username, password: password, block: { (user, NSError) -> Void in 

    self.actInd.stopAnimating() 

    if ((user) != nil) { 

     println("success user logged in") 

     self.performSegueWithIdentifier("toHome", sender: self) 
    }else { 

     var alert: UIAlertView = UIAlertView(title: "error", message: "You are logged in already", delegate: self, cancelButtonTitle: "Ok") 
     alert.show() 
    } 

希望有幫助。 祝你好運!

+0

嘿謝謝。我已經這樣做了。但在查看你的代碼時,我意識到我可以通過爲signUpButton設置一個目標來做我想做的事情。我想確認與確認密碼匹配的密碼,並且我可以在爲signUpButton設置的目標中執行此操作。出於某種原因,我覺得應該在shouldBeginSignUp中完成,這可能是他們的意圖。但正如你所說,他們的方法沒有被調用。謝謝您的意見。知道這不僅僅是我有這個問題,這些函數不會被調用,這是令人放心的。謝謝。 – epaus

+0

好夾。我試圖避免像你那樣爲signUp編寫代碼,只是將目標添加到已經存在的signUpButton中。但事實證明,我無法控制(即阻止)註冊這種方式,所以我會做你所做的,這是在SignUpViewController中創建自己的signupButton,併爲其添加一個操作...準確地拼出註冊碼。多煩人。爲什麼這些功能不能像他們應該的那樣工作。再次感謝您的幫助。 – epaus

0

我有同樣的問題,試試這個:

let logInController = LogInViewController() 
let signUpController = SignUpViewController() 
logInController.delegate = self 
signUpController.delegate = self 
logInController.signUpController = signUpController