[英]Xamarin.iOS, MVVMCross. Can I Access NavigationItem from TabBarController's root ViewController?
I use Xamarin.iOS and MVVMCross.我使用 Xamarin.iOS 和 MVVMCross。 My app's architecture is the following:
我的应用程序的架构如下:
+-----------------------+
| RootViewModel |
| RootViewController |
| [MvxRootPresentation] |
| |
+--------+----+---------+
| |
+-----------+ +------------+
| |
+----------+----------+ +-----------+---------+
|Tab1ViewModel | |Tab2ViewModel |
|Tab1ViewController | |Tab2ViewController |
|[MvxTabPresentation] | |[MvxTabPresentation] |
| | | |
+---------------------+ +---------------------+
The problem is, that the Navigation Bars are set up in the Tab ViewControllers.问题是,导航栏是在 Tab ViewControllers 中设置的。 I have to display some information on the NavigationItem.Title, which is stored in the RootViewModel.
我必须在 NavigationItem.Title 上显示一些信息,这些信息存储在 RootViewModel 中。 Can I have one, common Navigation Bar, which is initialize in the RootViewController?
我可以拥有一个在 RootViewController 中初始化的通用导航栏吗? Or if it's not possible, can I access RootViewModel from a TabViewController?
或者,如果不可能,我可以从 TabViewController 访问 RootViewModel 吗?
RootViewController
add the decoration to the class.RootViewController
将装饰添加到类中。[MvxRootPresentation(WrapInNavigationController = true)]
public partial class RootViewController : MvxTabBarViewController<RootViewModel>
[MvxTabPresentation(WrapInNavigationController = false, TabName = "Tab1Title", TabIconName = "Tab1Icon")]
public partial class Tab1ViewController : ViewController<Tab1ViewModel>
ViewDidLoad
to hide the indivdual navigation bars:ViewDidLoad
添加此项以隐藏单个导航栏:public override void ViewDidLoad()
{
base.ViewDidLoad();
if (NavigationController != null && NavigationController.NavigationBar != null)
{
NavigationController.NavigationBar.Hidden = true;
}
}
Bonus.奖金。 You can change the tab title translation in the
RootViewController
您可以在
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.