Tab bar, reload every time tab is pressed

前端 未结 7 731
梦毁少年i
梦毁少年i 2021-01-13 01:17

I am creating an app in which I have five tabs. I need to reload each controller every time when tab is pressed.

7条回答
  •  自闭症患者
    2021-01-13 01:54

    Example:

       // AppDelegate ( and  )
       // Creation tabbar and controllers               
        UIViewController* myController1 = [[UIViewController alloc] init] autorelease];
        UINavigationController* nav1 = [[[UINavigationController alloc] initWithRootViewController:myController1] autorelease];
    
        UIViewController* myController2 = [[UIViewController alloc] init] autorelease];
        UINavigationController* nav2 = [[[UINavigationController alloc] initWithRootViewController:myController2] autorelease];
    
        NSArray *array = [NSArray arrayWithObjects: myController1, myController2, nil];
    
        UITabBarController* tab = [[[UITabBarController alloc] init] autorelease];
        tab.viewControllers = array;
        tab.delegate = self; // <-- don't forget set delegate for TabBarController
    
    
        // TabBarController Delegate methods   
        - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
        {
                // Reload selected VC's view
            [viewController.view setNeedsDisplay];
        }
    

提交回复
热议问题