ios - 按下按钮时推送新的视图控制器
问题描述
我正在以编程方式在 Swift 5 中构建游戏,并希望从主菜单导航到游戏屏幕。这是我的代码:
func handleButtonsTapped() {
playButton.addTarget(self, action: #selector(pushGameViewController), for: .touchUpInside)
}
以及在点击时处理推送视图控制器的选择器:
@objc func pushGameViewController() {
let destinationVC = GameViewController()
navigationController?.pushViewController(destinationVC, animated: true)
}
当我在模拟器中点击按钮时,没有任何反应。我也handleButtonsTapped()
调用了我的viewDidLoad()
函数。
解决方案
有答案了!
在我的SceneDelegate.swift
我设置:
let menuViewController = UINavigationController(rootViewController: MenuViewController())
window?.rootViewController = menuViewController
现在它起作用了!谢谢大家的评论:)
推荐阅读
- c# - 如何延迟模拟httpMessageHandler?
- javascript - 如何在后端 Vb.net 上调用 Javascript 函数
- ruby - 为什么Ruby除法四舍五入?
- json - Python 解析 JSON 响应的 JSON 列表
- python - 将数据点加载到二维数组中
- visual-studio-code - 为 VSCode WSL 终端设置 umask
- azure-data-factory - Azure 数据工厂 - Azure 数据湖的增量加载
- javascript - 在 HTML 中间附加一个图表
- r - 如何使用 R 中插入符号包中的训练函数对分类预测变量进行逐步多元回归?
- flutter - 如何在 Column(或任何可滚动视图)内的 FlutterMap(flutter_map 包)上使用手势?