ios - 关于在 ViewControllers 之间传递数据的问题
问题描述
我有两个视图控制器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 模式的 Clean Architecture 之后做了那个示例
Github 中的项目链接:https ://github.com/JLPenaLopez/MyFiles
这是应用程序的一个示例:
您也可以关注这篇文章,其中非常清楚地解释了 Clean Architecture、MVVM 和其他模式,以遵循使用 Swift 在 iOS 上的良好实践
推荐阅读
- python - 显示嵌套模型的 InlineModelAdmin
- java - Android / java - 在 onClick 中使用计时器循环
- python - 如何在 django 模板中显示通过 django-celery-results 框架存储的 JSON 任务结果?
- javascript - 如何使用 JavaScript 制作像“Epic Sax Gandalf”这样的网络应用程序?
- c - 如何在 C 中定义“复杂”结构
- javascript - 如何从 Javascript 中获取主机名,使用户无法欺骗它?
- c++ - 对于 ETX/STX 对等多个字符,是否有类似于 std::quote 的内容
- swift - 将 float3 从 Swift 结构传递到金属着色器
- python - 如何将多个图像(子图)写入一张图像
- exception-handling - 异常处理程序未在自定义中间件 (.NET Core 2.0) 中捕获整个异常