[英]How to access data from multiple tabs in Multiplatform iOS Xamarin project
I created a new project by doing File -> New Solution -> Multiplatform -> App -> Native -> Native App in Visual Studio. 我通过在Visual Studio中执行文件->新解决方案->多平台->应用程序->本机->本机应用程序创建了一个新项目。 I am focusing on the iOS side of things.
我专注于iOS方面。
I am trying to modify this project. 我正在尝试修改此项目。 In the second tab of the generated app, I need to access all of the Items.
在生成的应用程序的第二个选项卡中,我需要访问所有项目。 Reusing ItemsViewModel seemed like a logical choice.
重用ItemsViewModel似乎是一个合理的选择。 However, the problem is that when I update the data in the second tab, changes are not reflected in the first tab, which is using a separate instance of ItemsViewModel in its respective ViewController.
但是,问题在于,当我更新第二个选项卡中的数据时,更改未反映在第一个选项卡中,该选项卡在其各自的ViewController中使用ItemsViewModel的单独实例。
My questions are: 我的问题是:
I solved this by creating a single instance of the ViewModel in the TabBarController. 我通过在TabBarController中创建ViewModel的单个实例来解决此问题。 In ViewDidLoad for each of the two ViewControllers where I needed the instance, I accessed the TabBarController's instance.
在需要实例的两个ViewController的每个ViewDidLoad中,我访问了TabBarController的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.