Tab bar, reboot every time you click a tab

I am creating an application in which I have five tabs. I need to restart each controller every time I click a tab.

+5
source share
6 answers

Put the code you want to reload in the view, the view of the whole view appears or appears.

All the best.

+13
source

Example:

   // AppDelegate ( and <UITabBarControllerDelegate> )
   // 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 view
        [viewController.view setNeedsDisplay];
    }
+3
source
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //other codes

    [self.tabBarController setDelegate:self]

    //other codes
    }

// UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if ([viewController respondsToSelector:@selector(reloadDataTemp)]) {
        [(YourViewController *)viewController reloadData];
    }
}
+2

So, write a method to redraw elements on your page and call it by clicking on a tab. I will edit this post if you provide more information about the problem you are facing.

0
source

If you are using uitableview use this

[tableview reloaddata];
0
source

I hope you are talking about web browsing, so web browsing should be reloaded every time the tab element moves, but simply implements [webview reload] in the delegate of the tab bar.

0
source

All Articles