用swift在viewdid中显示一个模态

tim*_*imT 9 ios swift

我是swift和ios编程的新手.我正在尝试在我的应用程序首次加载时显示模态视图.我遇到的问题是我的模态一直在反复出现.不知道我哪里出错了.

奖金问题:最终我希望这只会在用户第一次打开应用时发生.

class ViewController: UIViewController {

    var introModalDidDisplay = false

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func showIntroModal() {
        if (!introModalDidDisplay) {
            println(introModalDidDisplay)
            introModalDidDisplay = true
            let intro = self.storyboard?.instantiateViewControllerWithIdentifier("introModal") as IntroModalViewController
            intro.modalPresentationStyle = UIModalPresentationStyle.FormSheet
            self.presentViewController(intro, animated: true, completion: nil)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

tim*_*imT 4

找到了。我的“介绍”课程是延长ViewController而不是UIViewController......显然这很糟糕。谢谢您的帮助!抱歉,徒劳无功。