Setup looks like this:
LoginView MvxViewController
MainView MvxTabBarViewController
-Tab 1
- View1 (MvxViewController)
-Tab 2
- View1 (MvxViewController)
-Tab 3
- View1 (MvxViewController)
On View1 a I have a Tableview (List), will be filled always differently - depends on the tab.
Everything works fine so far. The problem I face now is, that when I'm in View1 and press the "Back" Button on the NavigationController I will get back to the "LoginView" instead the "MainView" (Rootview where the tabs are).
I found following command this.NavigationController.PopToRootViewController(true);
but I didn't find the right place to use it. (If it's even the right way)
I used this project to get the idea behind https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Views/TabBarController.cs
Any help appreciated!
EDIT:
I solved the problem now, by removing following code (commented section removed):
public class MyPresenter : MvxModalSupportTouchViewPresenter, ITabBarPresenterHost
{
public MyPresenter(UIApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
}
protected override UINavigationController CreateNavigationController(UIViewController viewController)
{
var toReturn = base.CreateNavigationController(viewController);
toReturn.NavigationBarHidden = false;
return toReturn;
}
public ITabBarPresenter TabBarPresenter { get; set; }
public override void Show(IMvxTouchView view)
{
//if (TabBarPresenter != null && view != TabBarPresenter)
//{
// TabBarPresenter.ShowView(view);
// return;
//}
base.Show(view);
}
}
I still don't understand the purpose of this code as it's making troubles. By removing it, everything works fine. (Code was from the example, to find here: https://github.com/slodge/MvvmCross-Tutorials/blob/0f313e3be66b06c110f587b653b9b0c831fb7164/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/ConferencePresenter.cs)
Generally you use a CustomPresenter for this type of logic - see N=25 in http://mvvmcross.wordpress.com for one example.
Your custom presenter can do things like:
Show
requests to navigation controllers sitting within the tab children: like on https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-25-Tabbed/Tabbed.Touch/Setup.cs#L58directly manipulating the UIViewController[]
array - e.g. something like
public override void Show(IMvxTouchView view)
{
base.Show(view);
if (view is MainView
&& MasterNavigationController.ViewControllers.Length > 1)
{
MasterNavigationController.ViewControllers = new UIViewController[]
{
MasterNavigationController.ViewControllers.Last()
};
}
}
For more on custom presenters, see https://github.com/slodge/MvvmCross/wiki/Customising-using-App-and-Setup#custom-presenters and http://slodge.blogspot.co.uk/2013/06/presenter-roundup.html
This article might be especially useful - http://deapsquatter.blogspot.co.uk/2013/06/custom-presenter-for-uitabbarcontroller.html