Reputation: 2200
I doing an application with various views types : MvxViewController, MvxTabBarViewController, ...
But when I want to do it, I meet difficulties : Following initial directives (http://bit.ly/1hLNMF3, http://bit.ly/1hNNY2g), I loose navigation back button among others.
So, I want to mix simple views and tabbed view without loosing Back button and without recode it (with NavigationItem.SetLeftBarButtonItem : http://bit.ly/1fsqGEC). Inspired by these solutions, I've do this :
Upvotes: 1
Views: 1444
Reputation: 2200
For the MvxTabBarViewController - main controller for item details :
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;
}
}
Moreover, I don't need to change Setup class.
Upvotes: 2