Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 关于在ViewController之间传递数据的问题_Ios_Swift_Uiviewcontroller - Fatal编程技术网

Ios 关于在ViewController之间传递数据的问题

Ios 关于在ViewController之间传递数据的问题,ios,swift,uiviewcontroller,Ios,Swift,Uiviewcontroller,我有两个视图控制器MainViewController和DetailViewController 我将变量从MainViewController传递到DetailViewController如下-> class MainController: UIViewController { ........... func showMatchDetailsView(matchId: Int) { let storyboard = UIStoryboard(name: "Match

我有两个视图控制器
MainViewController
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)
        }
}
匹配细节控制器

class MatchDetailsController: UIViewController {
    //MARK: Class variable
    var matchId: Int?
     .....
    }

您可以遵循此项目,其中显示带有数据列表的屏幕(UIViewController),并且所选项目的详细信息显示在另一个屏幕(UIViewController)中。我在使用MVVM、协调器和容器DI模式的干净体系结构之后做了这个示例

Github中的项目链接:

这是应用程序的一个示例:


您也可以遵循post,其中对干净的体系结构、MVVM和其他模式进行了非常清晰的解释,以遵循iOS上使用Swift的良好实践。此外,我使用的是MVVM设计模式。在ViewController中获取传递的数据是否正确?我看不出有任何问题。