将另一个视图控制器推入 UITabBarController 视图

发布于 2024-12-03 16:02:39 字数 357 浏览 1 评论 0原文

对于我的应用程序中的导航,我使用 UITabBarController。这工作正常,但在我的一个视图控制器中,我想将另一个视图控制器推入选项卡栏视图。 换句话说,我想用另一个视图控制器替换选定的视图控制器。 我使用以下代码执行此操作:

self.tabBarController.selectedViewController = self.otherViewController;

TabBarController 中的 viewController 列表不包含 otherViewController。 这个技巧在 IOS 4.3 中运行良好,但 IOS 5 不喜欢它。

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

For the navigation in my app I'm using a UITabBarController. This works fine, but in one of my viewcontrollers I want to push another view controller into the tabbar view.
In other words I want to replace the selected viewcontroller with another one.
I'm doing this with the following code:

self.tabBarController.selectedViewController = self.otherViewController;

The list of viewControllers in my TabBarController does not contain the otherViewController.
This trick works fine in IOS 4.3, but IOS 5 does not like it.

Does anyone know a solution which is accepted by IOS 5?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

埋葬我深情 2024-12-10 16:02:39

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

UIViewController *thisIsTheViewControllerIWantToSetNow;
int indexForViewControllerYouWantToReplace;

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

[tabbarViewControllers replaceObjectAtIndex:indexForViewControllerYouWantToReplace withObject:thisIsTheViewControllerIWantToSetNow];

self.tabbar.viewControllers = tabbarViewControllers;

[tabbarViewControllers release];

You want to REPLACE that view controller in the tabbar with another view Controller?
If so, you have to edit the viewControllers property in the tabbar by setting a new one. It would be something like:

UIViewController *thisIsTheViewControllerIWantToSetNow;
int indexForViewControllerYouWantToReplace;

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

[tabbarViewControllers replaceObjectAtIndex:indexForViewControllerYouWantToReplace withObject:thisIsTheViewControllerIWantToSetNow];

self.tabbar.viewControllers = tabbarViewControllers;

[tabbarViewControllers release];
z祗昰~ 2024-12-10 16:02:39

您不能仅在此选项卡上使用导航控制器或类似控制器吗?

无论如何这应该有效:

NSMutableArray *controllers = [NSMutableArray arrayWithArray:rootTabBarController.viewControllers];
[controllers replaceObjectAtIndex:rootTabBarController.selectedIndex withObject: newController];
rootTabBarController.viewControllers = controllers;

You can't just use a navigation controller or similar on this tab?

Anyway this should work:

NSMutableArray *controllers = [NSMutableArray arrayWithArray:rootTabBarController.viewControllers];
[controllers replaceObjectAtIndex:rootTabBarController.selectedIndex withObject: newController];
rootTabBarController.viewControllers = controllers;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文