【发布时间】:2021-01-09 16:01:05
【问题描述】:
我有两个视图 ControllerMainViewController 和 DetailViewController。
我像这样将变量从MainViewController 传递到DetailViewController ->
class MainController: UIViewController {
...........
func showMatchDetailsView(matchId: Int) {
let storyboard = UIStoryboard(name: "MatchDetails", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "MatchDetailsIdentifier") as! MatchDetailsController
controller.matchId = matchId // Is it a good practice?
controller.modalPresentationStyle = .fullScreen
navigationController?.pushViewController(controller, animated: true)
}
}
MatchDetailsController
class MatchDetailsController: UIViewController {
//MARK: Class variable
var matchId: Int?
.....
}
【问题讨论】:
-
另外,我正在使用 MVVM 设计模式。在 ViewController 中获取传递的数据是正确的方法吗?
-
我认为这没有任何问题。
标签: ios swift uiviewcontroller