Is it possible to change the actual ViewController on a UITabBarController in Monotouch

天涯浪子 提交于 2020-01-06 03:54:04

问题


I have a Monotouch App, on AppDelegate the RootViewController is a TabBarController, this TabBarController have 5 ViewControllers, lets say view1 to view5, i use

tabBarController.SelectedIndex = 2;

for select wich viewController will load when the app starts it works and the default tabBar is view3, now i need to show another viewController, lets say from view1 change to view5 with code, its possible? theres a way to emulate the clic on one of the buttons of my TabBar, that will work too...

thanks in advance

UPDATE:

I try:

view1.TabBarController.ViewControllers[4].PresentViewController(view5, true, delegate{});

And it works, but the view5 is presented over the TabBar, also i try this:

view1.TabBarController.TabBar.Items[4]. //i dont know wich method could invoke the click

Where i select the item of the tabbar i want to click

I think the solucion is close to this, the problem is that always the view5 shows over the TabBar and block it...

SOLVED:

view1.TabBarController.SelectedIndex = 2; //where the number is the view zero-bassed

回答1:


This what you want? You can call this from any click handler.

AppDelegate.Current.NavController.PushViewController(new View5(), true);

In my AppDelegate class I have:

public partial class AppDelegate : UIApplicationDelegate
{
    public static AppDelegate Current { get; private set; }
    public UINavigationController NavController { get; private set; }

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        Current = this;
        NavController = new UINavigationController();
        ...
    }
}

or do you want to just switch tabs: How to programmatically change views in TabBarViewController?



来源:https://stackoverflow.com/questions/10824821/is-it-possible-to-change-the-actual-viewcontroller-on-a-uitabbarcontroller-in-mo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!