I’m attempting to create a UITabBarController which implements a UINavigationBar, something I’d do in Xcode in a matter of minutes. However, I’m struggling using MVVMCross with MonoTouch. Some of the code is below –
From the first VC (this is for the user to accept terms & conditions, so once accepted, there’s no option to go back to it, hence the true flag) –
this.RequestNavigate<TabHostViewModel>(true);
My tabBar is set up like so, which works fine –
ViewControllers = new UIViewController[]
{
CreateTabFor("Home", "", ViewModel.homeViewModel),
CreateTabFor("History", "", ViewModel.journeyHistoryViewModel),
CreateTabFor("Contacts", "", ViewModel.contactsViewModel),
CreateTabFor("About", "", ViewModel.aboutViewModel),
};
…etc.
I try to set up the first view (HomeView in this case) like so in ViewDidLoad –
this.NavigationController.NavigationBar.TintColor = myNavBarColour;
However, it seems that NavigationController in undefined, unless I create my own when I set up the TabBar –
UIViewController HomeViewController = CreateTabFor("Home", "", ViewModel.homeViewModel);
UINavigationController HomeNavController = new UINavigationController(HomeViewController);
ViewControllers = new UIViewController[]
{
HomeNavController,
CreateTabFor("History", "", ViewModel.journeyHistoryViewModel),
CreateTabFor("Contacts", "", ViewModel.contactsViewModel),
CreateTabFor("About", "", ViewModel.aboutViewModel),
};
Now I can do whatever I like with the navigation bar, but the trouble is I have two navigation bars, one at the top with no title, and the new one I’ve just created immediately below it.
Anyone with any thoughts?
Many thanks.
I’m not entirely clear on your setup.
However, I think what you are looking for is what the conference sample does
Within this sample:
This code is:
The navigation is then intercepted inside the Presenter logic (configured in the AppDelegate) – the ConferencePresenter defers the ShowView logic to:
This logic is a little complicated, but the aim of this navigation and presenter design is to allow you to customise the presentation to suit the application. This can also be changed dynamically at runtime – so you can, for example, choose to use different presentation logic on a iPad instead of a iPhone.