Tab bar, reload every time tab is pressed

心已入冬 提交于 2019-12-01 06:03:23

Put the code you want to reload, in the view will appear or in view did appear of all the view.

All the best.

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's view
        [viewController.view setNeedsDisplay];
    }
 - (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];
    }
}

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

if you are you are using the uitableview use this

[tableview reloaddata];

I hope you are talking about the webview the webview should reload every time a tabbar item is navigated well just implement [webview reload] in the tab bar delegate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!