如何在 Xamarin mvvmcross 项目中为 IOS 修复 MvxTabViewController 内的导航?
How to fix navigation inside MvxTabViewController for IOS in Xamarin mvvmcross project?
在我的应用程序中,我有 LoginView,然后是 MainView,它是带有两个选项卡的 MvxTabBarViewController。这是我的 MainView 代码:
public class MainView : MvxTabBarViewController<MainViewModel>
{
private bool _constructed;
public MainView()
{
_constructed = true;
// need this additional call to ViewDidLoad because UIkit creates the view before the C# hierarchy has been constructed
ViewDidLoad();
}
public override void ViewDidLoad()
{
if (!_constructed)
return;
base.ViewDidLoad();
Title = "SampleTabs";
View.BackgroundColor = UIColor.Red;
var viewControllers = new List<UIViewController>();
viewControllers.Add(CreateTabFor("Second", ViewModel.TabEvents, 0));
viewControllers.Add(CreateTabFor("First", ViewModel.TabDashboard, 1));
ViewControllers = viewControllers.ToArray();
CustomizableViewControllers = new UIViewController[] { };
// SelectedViewController = ViewControllers[1];
}
private UIViewController CreateTabFor(string title, IMvxViewModel viewModel, int index)
{
var controller = new UINavigationController();
var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
screen.Title = title;
// screen.TabBarItem = new UITabBarItem(title, null, index);
screen.TabBarItem = new UITabBarItem(UITabBarSystemItem.Search, index);
controller.PushViewController(screen, false);
controller.NavigationBarHidden = true;
return controller;
}
}
问题出在标签项上,我无法在显示初始标签后将其更改为第二个。选项卡很简单,只有背景颜色发生变化。欢迎任何帮助。
已修复!问题出在核心而不是标签视图。
在我的应用程序中,我有 LoginView,然后是 MainView,它是带有两个选项卡的 MvxTabBarViewController。这是我的 MainView 代码:
public class MainView : MvxTabBarViewController<MainViewModel>
{
private bool _constructed;
public MainView()
{
_constructed = true;
// need this additional call to ViewDidLoad because UIkit creates the view before the C# hierarchy has been constructed
ViewDidLoad();
}
public override void ViewDidLoad()
{
if (!_constructed)
return;
base.ViewDidLoad();
Title = "SampleTabs";
View.BackgroundColor = UIColor.Red;
var viewControllers = new List<UIViewController>();
viewControllers.Add(CreateTabFor("Second", ViewModel.TabEvents, 0));
viewControllers.Add(CreateTabFor("First", ViewModel.TabDashboard, 1));
ViewControllers = viewControllers.ToArray();
CustomizableViewControllers = new UIViewController[] { };
// SelectedViewController = ViewControllers[1];
}
private UIViewController CreateTabFor(string title, IMvxViewModel viewModel, int index)
{
var controller = new UINavigationController();
var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
screen.Title = title;
// screen.TabBarItem = new UITabBarItem(title, null, index);
screen.TabBarItem = new UITabBarItem(UITabBarSystemItem.Search, index);
controller.PushViewController(screen, false);
controller.NavigationBarHidden = true;
return controller;
}
}
问题出在标签项上,我无法在显示初始标签后将其更改为第二个。选项卡很简单,只有背景颜色发生变化。欢迎任何帮助。
已修复!问题出在核心而不是标签视图。