我正在使用 swift 开发一个简单的 IOS 应用程序。在我的应用程序中,我需要从另一个控制器以编程方式打开新控制器。所以我在故事板中添加了另一个场景。
然后我为从 UIViewController 继承的新控制器添加了一个新类。这是新控制器的代码
import UIKit
class ReplayController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
然后,我尝试在代码中像这样从主控制器打开新的控制器视图(ReplayController)。
func gameOver()
{
let replayController = ReplayController()
present(replayController, animated: true, completion: nil)
}
当我调用该函数时,它只是弹出空白屏幕。屏幕上什么也没有出现。出了什么问题,我该如何解决?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句