为什么parentViewController,presentViewController和PresentedViewController始终为nil

时间:2015-07-10 09:12:04

标签: ios swift uiviewcontroller sprite-kit

我有一个带有几个ViewControllers的简单应用程序,我需要知道当我在VC中时,我来自哪个VC(第一个除外)。所有VC都在故事板中创建,我使用以下代码浏览VC:

class FirstVC: UIViewController
{    
    func ShowStartVC()
    {
        if gFirstStart
        {
            let vc = self.storyboard!.instantiateViewControllerWithIdentifier("EvalUserLevelVC") as EvalUserLevelVC
            self.presentViewController(vc, animated: false, completion: nil)
        }
        else
        {
            let vc = self.storyboard!.instantiateViewControllerWithIdentifier("ChoixLevelVC") as ChoixLevelVC
            self.presentViewController(vc, animated: true, completion: nil)
        }
    }

    func ShowPrefsVC()
    {
        let vc = self.storyboard!.instantiateViewControllerWithIdentifier("PrefsVC") as PrefsVC
        self.presentViewController(vc, animated: true, completion: nil)
    }
}


class FirstVCSceneClass: SKScene
{
    var VCFirst = FirstVC?()

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
    {    
        for touch: AnyObject in touches
        {
            let location = touch.locationInNode(self)

            switch self.nodeAtPoint(location).name!
            {
            case "Start":
                VCFirst?.ShowStartVC()
                self.paused = true

            case "Preferences":
                VCFirst?.ShowPrefsVC()
                self.paused = true

            default:
                break
            }
        }
    }
}

在" ChoixLevelVC"上面的代码中可以从这里和另一个VC(完全相同的方式)调用,我需要知道从哪个VC调用它。我的理解是属性" presentViewController"当我从" ChoixLevelVC"访问它时,应该有这些信息。 UIViewController类

但如果我将以下代码放在" ChoixLevelVC"一切都是零,虽然我希望找到" FirstVC"在属性" presentsViewController"

class ChoixLevelVC: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource
{
    override func viewDidLoad()
    {
        println("ParentViewController : \(self.parentViewController)")
        println("presentingViewController : \(self.presentingViewController)")
        println("presentedViewController : \(self.presentedViewController)")
    }
}

每个VC都是一样的。为了正确设置这些属性,我需要做些什么吗?

0 个答案:

没有答案