如何更改选项卡栏的选定索引

发布于 2024-10-13 00:13:07 字数 181 浏览 12 评论 0原文

在我的应用程序中有一个选项卡栏。在选项卡栏的某个元素(例如选项卡栏索引 1 处的元素)上有一些按钮,单击它们将引导至选项卡栏的其他元素(例如选项卡栏索引 3 处的元素)下的某些页面。

我能够导航到所需的页面,但选项卡栏选择未正确显示。即使页面位于第三个选项卡栏元素中,也会选择第一个元素。

怎么解决这个问题呢?想法请

In my app there is a tab bar. On one of the elements of the tabbar (say element at index 1 of the tabbar) there are some buttons on clicking them will guide to some pages which are under some other element of the tabbar(say element at index 3 of the tabbar).

I was able to navigate to the required page but the tabbar selection is not properly displayed. Even though the page is in 3rd tab bar element, the 1st element is selected.

How to solve this? Ideas plz

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

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

发布评论

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

评论(1

最丧也最甜 2024-10-20 00:13:07

最后我得到了解决方案。

在回答这个问题之前,让我告诉你一件事,我认为所有问题的发生都是因为选项卡栏是通过代码实现的。如果是通过 nib 完成的话,问题就不会出现。

我通过以下方式解决了这个问题:

我没有使用 self.navigationcontoller 推送所需的视图控制器的对象,而是对选项卡栏的所需视图进行了类型转换。

还请检查代码

TabViewController *tabBarController = [[TabViewController alloc]
                                                initWithNibName:GENERIC_TAB_NIB 
                                                bundle:nil];

DetailsViewController *detailsVC = [[DetailsViewController alloc]  initWithNibName:DETAILS_NIB
                                                         bundle:nil];
        UINavigationController *navigationController = (UINavigationController *)[tabBarController.viewControllers objectAtIndex:1];
        [navigationController pushViewController:detailsVC animated:YES];
        [detailsVC release];

Finally I got the solution.

Before going into the answer let me tell u one thing, i think all the problem occured because the tab bar was implemeented via code. If it was done through nib then the problem won't come .

I solved this problem in the following manner:

Instead of pushing the required view controller's object using self.navigationcontoller i typecasted the tabbar's required view.

Please check the code also

TabViewController *tabBarController = [[TabViewController alloc]
                                                initWithNibName:GENERIC_TAB_NIB 
                                                bundle:nil];

DetailsViewController *detailsVC = [[DetailsViewController alloc]  initWithNibName:DETAILS_NIB
                                                         bundle:nil];
        UINavigationController *navigationController = (UINavigationController *)[tabBarController.viewControllers objectAtIndex:1];
        [navigationController pushViewController:detailsVC animated:YES];
        [detailsVC release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文