In the video he shows how to hide the navigation bar of the root UINavigationController so that you don't land up with a double bar on top. This is all fine for demo purposes (Stuart has thick skin and is only interested in progress) but what we really want is is for the UITabBarController to be the root controller. Apple recommends this approach and I have experienced some weirdness when not following this rule (especially when applying themes).
Unfortunately the presenter below does require a small change to the MvvmCross libraries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IPhoneViewPresenter : MvxModalNavSupportTouchViewPresenter | |
{ | |
public IPhoneViewPresenter (UIApplicationDelegate applicationDelegate, UIWindow window) | |
:base(applicationDelegate, window) | |
{ | |
} | |
HomeView homeView; | |
protected override UIViewController CurrentTopViewController | |
{ | |
get { return MasterNavigationController.TopViewController; } | |
} | |
public override UINavigationController MasterNavigationController | |
{ | |
get{ | |
var navController = homeView.ViewControllers [homeView.SelectedIndex]; | |
return (UINavigationController)navController; | |
} | |
} | |
public override void Show (Cirrious.MvvmCross.Touch.Views.IMvxTouchView view) | |
{ | |
if (homeView != null) | |
base.Show (view); | |
else{ | |
homeView = view as HomeView; | |
base.SetWindowRootViewController (homeView); | |
} | |
} | |
} |
HomeView is your MvxTabBarController which we will keep a reference to. Show is overridden to save the reference and sets HomeView as the root view controller using the base method. If anything else but the HomeView is shown the base Show is called. MasterNavigationController will return the UINavigationController of the currently selected tab. The idea is that you have a UINavigationController as the root controller in each tab. CurrentTopViewController simply returns the top most view of MasterNavigationController.
The change in the MvvmCross library I mentioned earlier is in MvxTouchViewPresenter. In order for the above to work the following change is required:
What we really need is a base presenter that doesn't force a UINavigationController as the root. Of course you can roll your own Presenter from scratch (MvvmCross is flexible that way) but that's a lot more code. Something to work on for next time...
2 comments:
Hello your blog is sharing great information on this topic, we are providing
Custom controllers
Thanks for sharing this information.
Thanks! It seems that the change in MvxTouchViewPresenter is in the main branch now.
https://github.com/MvvmCross/MvvmCross/blob/3.5/Cirrious/Cirrious.MvvmCross.Touch/Views/Presenters/MvxTouchViewPresenter.cs
Post a Comment