![](/img/trans.png)
[英]Xamarin, iOS Get Instance of viewcontroller from tabbarcontroller
[英]Xamarin.iOS, MVVMCross. Can I Access NavigationItem from TabBarController's root ViewController?
我使用 Xamarin.iOS 和 MVVMCross。 我的應用程序的架構如下:
+-----------------------+
| RootViewModel |
| RootViewController |
| [MvxRootPresentation] |
| |
+--------+----+---------+
| |
+-----------+ +------------+
| |
+----------+----------+ +-----------+---------+
|Tab1ViewModel | |Tab2ViewModel |
|Tab1ViewController | |Tab2ViewController |
|[MvxTabPresentation] | |[MvxTabPresentation] |
| | | |
+---------------------+ +---------------------+
問題是,導航欄是在 Tab ViewControllers 中設置的。 我必須在 NavigationItem.Title 上顯示一些信息,這些信息存儲在 RootViewModel 中。 我可以擁有一個在 RootViewController 中初始化的通用導航欄嗎? 或者,如果不可能,我可以從 TabViewController 訪問 RootViewModel 嗎?
RootViewController
將裝飾添加到類中。[MvxRootPresentation(WrapInNavigationController = true)]
public partial class RootViewController : MvxTabBarViewController<RootViewModel>
[MvxTabPresentation(WrapInNavigationController = false, TabName = "Tab1Title", TabIconName = "Tab1Icon")]
public partial class Tab1ViewController : ViewController<Tab1ViewModel>
ViewDidLoad
添加此項以隱藏單個導航欄:public override void ViewDidLoad()
{
base.ViewDidLoad();
if (NavigationController != null && NavigationController.NavigationBar != null)
{
NavigationController.NavigationBar.Hidden = true;
}
}
獎金。 您可以在RootViewController
更改選項卡標題翻譯
protected override void SetTitleAndTabBarItem(UIViewController viewController, MvxTabPresentationAttribute attribute)
{
attribute.TabName = _yourLocalizationService.Translate(attribute.TabName);
base.SetTitleAndTabBarItem(viewController, attribute);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.