UIKIt 使相同的视图模型实例可用于所有选项卡

发布于 01-16 22:07 字数 294 浏览 3 评论 0原文

我想在选项卡式 UIKit 应用程序的不同选项卡上使用相同的视图模型。在 SwiftUI 中,我可以在根目录上创建一个 @StateObject var 并将其作为 .environmentObject 传递给包含 TabView 的 ContentView 这将使其可用于选项卡项目。使用带有 UITabBarController 的 UIKIt 应用程序实现此目的的最佳方法是什么?

我的想法:将视图模型引用传递给每个视图控制器?或者使用委托/组合?

I want to use the same view model across different tabs of my tabbed UIKit application. In SwiftUI, I could create a @StateObject var on the root and pass it as an .environmentObject to the ContentView containing the TabView which would make it available for the tab items. What would be the best way to achieve this having a UIKIt application with a UITabBarController ?

My thoughts: pass the view model reference to each of the view controllers ? Or use delegates / Combine ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文