尝试在视图不在窗口层次结构中的ViewController上显示ViewController

时间:2015-02-11 03:27:42

标签: ios swift uiviewcontroller parse-platform pfloginviewcontroller

我查看过关于SOF的其他问题,它们与我的问题很接近但不完全一样。

我试图通过PFLogInViewController继承MyLogInViewController来加载ParseUI,我使用viewDidLoad但动画没有显示(因为它已经加载了我认为)和下面显示窗口层次结构警告。然后我尝试viewDidAppear但是loginView现在反复显示不间断。 (也许是因为观点不断出现?)

我试过viewWillApear,动画确实无效。 Warning: Attempt to present <myloginbeta1.MyLogInViewController: 0x7fa0185f0b30> on <myloginbeta1.MyLogInViewController: 0x7fa0185d4110> whose view is not in the window hierarchy!

我尝试viewWillLayoutSubviews,不间断重复。

我试过viewDidLayoutSubviews,动画没有用。 Warning: Attempt to present <myloginbeta1.MyLogInViewController: 0x7fa0185f0b30> on <myloginbeta1.MyLogInViewController: 0x7fa0185d4110> whose view is not in the window hierarchy!

我是否应该尝试将动画正确显示并且没有警告信息?

这是我的代码:

import UIKit
import ParseUI
class MyLogInViewController: PFLogInViewController, PFLogInViewControllerDelegate, FBLoginViewDelegate, PFSignUpViewControllerDelegate {

override func viewDidLoad() {

    super.viewDidLoad()

//This func works with warning below and the animation part is not working since it is called before the view appear.
//Warning: Attempt to present <myloginbeta1.MyLogInViewController: 0x7fa0185f0b30> on <myloginbeta1.MyLogInViewController: 0x7fa0185d4110> whose view is not in the window hierarchy!
    // Do any additional setup after loading the view.
}

override func viewDidAppear(animated: Bool) {
//This func doesn't work, viewDidAppear will keep repeating
}

override func viewWillAppear(animated: Bool) {

//This func works but the animation part is not working since it is called before the view appear.

    self.view.backgroundColor = UIColor(red: 241/255.0, green: 224/255.0, blue: 174/255.0, alpha: 1.0)

    var logInController:MyLogInViewController  = MyLogInViewController()

    logInController.fields = (PFLogInFields.UsernameAndPassword
        | PFLogInFields.LogInButton
        | PFLogInFields.SignUpButton
        | PFLogInFields.PasswordForgotten
        | PFLogInFields.DismissButton
        | PFLogInFields.Facebook
        | PFLogInFields.Twitter)

    logInController.delegate = self

    logInController.facebookPermissions = ["public_profile", "email", "user_friends"]

    let logoView = UIImageView(image: UIImage(named:"logo.png"))
    self.logInView.logo = logoView

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

func logInViewController(controller: MyLogInViewController, didLogInUser user: PFUser!) -> Void {
    self.dismissViewControllerAnimated(true, completion: nil)   
    println("Login Successful")
}

func logInViewControllerDidCancelLogIn(controller: MyLogInViewController) -> Void {
    self.dismissViewControllerAnimated(true, completion: nil)
}

谢谢,任何帮助将不胜感激! : - )

更新:我在发布此问题之前已经检查了whose view is not in the window hierarchy。使用viewDidAppear的解决方案没有帮助,loginView将不断显示。

0 个答案:

没有答案