xcode - 从 UIViewcontroller 链接到 UITabBarController 页面

标签 xcode uiviewcontroller uitabbarcontroller

我有一个链接问题,我使用的是 xib,而不是 Storyboard。

我有一个 UITabBarController 系统和其他一些远离标签栏系统的 View Controller 。我的问题是我可以使用按钮从其中一个 View Controller 链接回 UITabBarController 上的某个页面吗?

最佳答案

UITabBarController 是父级,选项卡下的 ViewControllers 是子级。您可以使用 parentViewController 属性从 childViewControllers 访问 TabBarController。

因此,如果您有一个带有 2 个选项卡的 UITabBarController,其中包含 ViewController1 和 ViewController2,您可以在其中任何一个中使用这一行。

UITabBarController* tabBarController = (UITabBarController*)self.parentViewController;
// So if for example you have a button in ViewController2 and you need to show
// ViewController1 when it is pressed, you can do the following
tabBarController.selectedIndex = 0;

关于xcode - 从 UIViewcontroller 链接到 UITabBarController 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13344660/

相关文章:

iphone - 如何添加 ViewController View 作为 subview

ios - iOS 中的全局工具栏?

iOS Storyboard 应用 + AppDelegate

ios - .plist文件丢失但当前存在,因此无法运行应用

ios - CMTimeMake 用户选择器

ios - 非全屏和全屏 UIViewController 之间的漂亮滑动过渡

ios - 将 View Controller 从一个 Storyboard移动或复制到另一个

ios - iPhone 静态库 Clang/LLVM 错误 : non_lazy_symbol_pointers

iphone - UITabBarController 和 UINavigationController 交互

ios - UIView 覆盖全屏,覆盖来自 UITabBarController 的选项卡