一般来说,我是 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)
}
}
}
最佳答案
找到了。我的“介绍”类正在扩展 ViewController
而不是 UIViewController
...显然这很糟糕。谢谢您的帮助!对不起,我的胡思乱想。
关于ios - 在 viewdidappear 中快速呈现模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26389606/