本文介绍了是否可以在 Monotouch 中更改 UITabBarController 上的实际 ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Monotouch 应用,在 AppDelegate 上,RootViewController 是一个 TabBarController,这个 TabBarController 有 5 个 ViewController,比如说 view1 到 view5,我使用

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;

为了选择应用程序启动时将加载哪个viewController,它可以工作,默认tabBar 是view3,现在我需要显示另一个viewController,比如说从view1 更改为view5 的代码,这可能吗?有一种方法可以模拟我的 TabBar 的一个按钮上的 clic,它也可以工作...

for select which 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? there's a way to emulate the clic on one of the buttons of my TabBar, that will work too...

更新:

我试过了:

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

它可以工作,但是 view5 显示在 TabBar 上,我也试试这个:

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

view1.TabBarController.TabBar.Items[4]. //I don't know which method could invoke the click

我选择要点击的标签栏项目的位置

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

我认为解决方案接近于此,问题是 view5 总是显示在 TabBar 上并阻止它...

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

已解决:

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

推荐答案

这就是你想要的?您可以从任何点击处理程序调用它.

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

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

在我的 AppDelegate 类中,我有:

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();
        ...
    }
}

还是只想切换标签页:如何以编程方式更改 TabBarViewController 中的视图?

这篇关于是否可以在 Monotouch 中更改 UITabBarController 上的实际 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 05:18