首页 > 解决方案 > 从 TabBarController 调用带有 Button 的 ViewController

问题描述

我想在我的 Xamarin.ios 应用程序中调用几个视图。这个应用程序有一个 TabBarController,它可以正常工作。现在我想调用添加到我的 TabBarController 中的视图,并在 MainPage 上使用按钮。

用户应该走的方式应该是这样的:

  1. 单击显示 ActionSheet 的图片(按钮)。这显示了有关侧面的简短说明,并提供了两个选项,“确定”和“显示视图”。
  2. 用户按下“显示视图”,将显示侧面。<-这是问题所在。

我尝试了以下方法:

this.TabBarController.PresentViewController(this.TabBarController.ViewControllers[1], true, null);

TabBarController.SelectedIndex = 1;
PerformSegue("Einstellungen", sender: this.TabBarController);

但没有任何效果。我刚刚收到一些错误,应用程序崩溃了......

有人可以给我一个好主意吗?

标签: ipadviewxamarin.iosuitabbarcontroller

解决方案


要更改 UITabBarController 的选项卡,您所要做的就是更改当前索引。

this.TabBarController.SelectedIndex =*TabIndex*;

TabBarController 是您的 UITabBarController 对象的引用,请确保您在 MainThread 上执行此操作,并且一切正常。

请检查此以获取更多详细信息https://docs.microsoft.com/en-us/xamarin/ios/user-interface/controls/creating-tabbed-applications

如果您有任何疑问,请随时回复


推荐阅读