为什么我需要点击 tabBarViewController 项目两次才能导航到不同的视图控制器 - iOS [英] Why i need to tap tabBarViewController item Twice to navigate to different View Controller - iOS

查看:30
本文介绍了为什么我需要点击 tabBarViewController 项目两次才能导航到不同的视图控制器 - iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中我的菜单屏幕上有一个 TabBar.它有 5 个视图控制器(5 个选项卡).我分别在索引 3 和 4 处分配了 2 个视图控制器,因此如果我单击这两个中的任何一个,它们将导航到所需的视图控制器.

I Am Working on an Application where there is a TabBar present on My Menu Screen. It has 5 view Controllers (5 Tabs). I am assigning 2 view controllers at the index 3 and 4 respectively, so that if i click on any of the two, they will navigate to their desired view Controllers.

如果我第一次在标签栏中选择一个项目,一切都会很好.但是,当我回到该视图控制器并尝试再次按下它时,该项目被选中进行第一次单击,但不会导航到视图控制器.我必须再次单击它才能执行相同的操作.即我必须点击它两次才能导航.

Every thing works well if i select an item in tab bar for the first time. But, when i come back to that view controller and try to press it again , then the item gets selected for first click, but does not navigate to the view controller.I have to click it again to perform that same action. i.e. I have to click it twice for Navigation.

我在这里发布了一些关于我的问题的代码.

Here i have posted some code regarding my question.

//...In my appdelegate class
CalenderScreen *calender=[[CalenderScreen alloc]initWithNibName:@"CalenderScreen" bundle:nil];
    NewsScreen *news=[[NewsScreen alloc]initWithNibName:@"NewsScreen" bundle:nil ];

    UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:menu];
    UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:emergency];
    UINavigationController *nav4=[[UINavigationController alloc] initWithRootViewController:help];
    UINavigationController *nav3=[[UINavigationController alloc]initWithRootViewController:calender];
    UINavigationController *nav5 =[[UINavigationController alloc]initWithRootViewController:news];

//tab bar initialization
tab=[[UITabBarController alloc]init];
    tab.viewControllers=[[NSArray alloc]initWithObjects:nav1,nav2,nav4,nav5,nav3 ,nil];
    UITabBarItem *tabItem = [[[tab tabBar] items] objectAtIndex:0];
    [tabItem setTitle:@"Menu"];
    tabItem.image=[UIImage imageNamed:@"Menu.png"];
    UITabBarItem *tabItem1 = [[[tab tabBar] items] objectAtIndex:1];
    [tabItem1 setTitle:@"Emergency"];
    tabItem1.image=[UIImage imageNamed:@"Emergency.png"];
    UITabBarItem *tabItem2 = [[[tab tabBar] items] objectAtIndex:2];
    [tabItem2 setTitle:@"HelpLine"];
    tabItem2.image=[UIImage imageNamed:@"helpline.png"];
    UITabBarItem *tabItem3 = [[[tab tabBar] items] objectAtIndex:3];
    [tabItem3 setTitle:@"News"];
    tabItem3.image=[UIImage imageNamed:@"News.png"];
    UITabBarItem *tabItem4 = [[[tab tabBar] items] objectAtIndex:4];
    [tabItem4 setTitle:@"Raise Ticket"];
    tabItem4.image=[UIImage imageNamed:@"ticket.png"];

     self.window.rootViewController=tab;

    [self.window makeKeyAndVisible];

在我的视图控制器类中,我有以下代码

And in my view controller class, I am having below code

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NewsScreen *news=[[NewsScreen alloc] initWithNibName:@"NewsScreen" bundle:nil];

if (tabBarController.selectedIndex==3)
{
    NSUInteger index=3; //assign value here
    UINavigationController *nv = [[tabBarController viewControllers] objectAtIndex:index];//index of your NewsScreen controller
    [tabBarController setSelectedIndex:3];

    NSArray *array =[nv viewControllers];
    for (news in array)
    {
        if ([news isKindOfClass:[NewsScreen class]])
        {
            news.loginbacklbl.hidden=YES;
        }
    }
}

我担心的是,当我第一次点击 NewsScreen 时,它工作正常.但是当我回来并尝试单击 tabBar 上的 NewScreen 项目时,它需要单击两次才能完成事件.任何人都可以帮助我为什么会发生这种情况,以及应该做些什么来避免这个问题.请帮帮我.任何帮助表示赞赏.谢谢.

My worry is, when i click on NewsScreen for the first time, it works fine. But when i come back and try to click the NewScreen item on tabBar, it requires two clicks for me two get the event done. Can anybody help me why this happens, and what should be done to avoid this issue. Please help me out. Any help is appreciated. Thank you.

推荐答案

单击用于激活您当前的选项卡 &双击进入 t 根...告诉客户端这是默认行为.

Single click is used to activate your current tab & double click to go t root... Tell client this is default behavior.

如果你还想覆盖,你必须制作自定义标签栏.

If you still want to override, you have to make custom tab bar.

这篇关于为什么我需要点击 tabBarViewController 项目两次才能导航到不同的视图控制器 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆