【发布时间】:2014-12-10 22:43:18
【问题描述】:
总的来说,我是 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)
}
}
}
【问题讨论】:
-
只需要在 override func viewDidLoad() { super.viewDidLoad() showIntroModal() } 中定义