Tab bar, reload every time tab is pressed

蹲街弑〆低调 提交于 2019-12-01 03:46:59

问题


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


回答1:


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

All the best.




回答2:


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];
    }



回答3:


 - (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];
    }
}



回答4:


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.




回答5:


if you are you are using the uitableview use this

[tableview reloaddata];



回答6:


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.




回答7:


Swift 5


func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        let vc = self.viewControllers?[1] as? stepVC // ViewController That need to be loaded
        vc?.viewDidLoad()

    }


来源:https://stackoverflow.com/questions/5946511/tab-bar-reload-every-time-tab-is-pressed

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