objective-c - 将另一个 View Controller 插入 UITabBarController View

标签 objective-c ios uitabbarcontroller

对于我的应用程序中的导航,我使用的是 UITabBarController。这工作正常,但在我的一个 View Controller 中,我想将另一个 View Controller 插入标签栏 View 。 换句话说,我想用另一个替换选定的 View Controller 。 我正在使用以下代码执行此操作:

self.tabBarController.selectedViewController = self.otherViewController;

我的 TabBarController 中的 viewController 列表不包含 otherViewController。 这个技巧在 IOS 4.3 中工作正常,但 IOS 5 不喜欢它。

有人知道 IOS 5 接受的解决方案吗?

最佳答案

您想用另一个 View Controller 替换标签栏中的 View Controller 吗? 如果是这样,您必须通过设置新属性来编辑选项卡栏中的 viewControllers 属性。它会是这样的:

UIViewController *thisIsTheViewControllerIWantToSetNow;
int indexForViewControllerYouWantToReplace;

NSMutableArray *tabbarViewControllers = [self.tabbar.viewControllers mutableCopy];

[tabbarViewControllers replaceObjectAtIndex:indexForViewControllerYouWantToReplace withObject:thisIsTheViewControllerIWantToSetNow];

self.tabbar.viewControllers = tabbarViewControllers;

[tabbarViewControllers release];

关于objective-c - 将另一个 View Controller 插入 UITabBarController View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7363434/

相关文章:

ios - 跨多个 View 共享导航栏的最佳方式?

ios - Swift:将选项卡栏放在 View 前面

ios - 颠倒呈现 UIActivityViewController

ios - 用\w匹配非英文字符

ios - 如何使用 UITabBarController 制作 "scroll-to-fullscreen"?

iphone - 用于从 iOS 将视频上传到 youtube 的开源 API?

ios - 背景图像不会在 iPhone 和 iPad 上调整大小。没有任何效果

iOS PayUMoney SDK key 无效

ios - 数据结构和数据模型之间的区别 - 例如?

ios - 键值观察的新手;为什么我无法在我的 AppDelegate 中监控 int 的值?