UIKIt 使相同的视图模型实例可用于所有选项卡
我想在选项卡式 UIKit 应用程序的不同选项卡上使用相同的视图模型。在 SwiftUI 中,我可以在根目录上创建一个 @StateObject var
并将其作为 .environmentObject
传递给包含 TabView 的
这将使其可用于选项卡项目。使用带有 UITabBarController 的 UIKIt 应用程序实现此目的的最佳方法是什么?ContentView
我的想法:将视图模型引用传递给每个视图控制器?或者使用委托/组合?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论