Xamarin.iOS MvvmCross,后退导航按钮和标签

时间:2014-04-30 13:05:13

标签: ios tabs xamarin.ios xamarin mvvmcross

我使用各种视图类型执行应用程序:MvxViewController,MvxTabBarViewController,...

但是当我想要这样做时,我遇到了困难:遵循初始指令(http://bit.ly/1hLNMF3http://bit.ly/1hNNY2g),我忽略了导航后退按钮等。

所以,我想混合简单的视图和选项卡式视图而不会丢失Back按钮而不重新编码它(使用NavigationItem.SetLeftBarButtonItem:http://bit.ly/1fsqGEC)。受这些解决方案的启发,我这样做了:

1 个答案:

答案 0 :(得分:2)

  • 项目列表(简单的MvxTableController)
  • 我的项目的详细视图 - MvxTabBarViewController,有3个标签(每个标签附有1个视图)

对于MvxTabBarViewController - 项目详细信息的主控制器:

public partial class SecondView : MvxTabBarViewController {
    private int _count = 0;

    public SecondView() {
        ViewDidLoad();
    }

    public new SecondViewModel ViewModel {
        get { return (SecondViewModel)base.ViewModel; }
        set { base.ViewModel = value; }
    }

    public override void ViewDidLoad() {
        base.ViewDidLoad();
        if (ViewModel == null) return;
        var viewControllers = new UIViewController[] {
            CreateTabFor ("tab 1", "t1", ViewModel.Tab1);
            CreateTabFor ("tab 2", "t2", ViewModel.Tab2);
            CreateTabFor ("tab 3", "t3", ViewModel.Tab3);
        }
        ViewControllers = viewControllers;
        CustomizableViewControllers = new UIViewController[0] { }
        SelectedViewController = ViewControllers [0]
    }

    private UIViewController CreateTabFor (string tabTitle, string tabImage, IMvxViewModel viewModel) {
        var controller = new UITabViewController (); 
        var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
        controller.TabBarItem = new UITabBarItem (tabTitle, UIImage.FromBundle("Images/" + tabImage + ".png"), _count);
        _count++;
        controller.Add (screen.View);
        return controller;
    }
}

此外,我不需要更改安装程序类。