Tab bar, reload every time tab is pressed
16,630
Solution 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.
Solution 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];
}
Solution 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];
}
}
Author by
Hiren
Updated on June 27, 2022Comments
-
Hiren almost 2 years
I am creating an app in which I have five tabs. I need to reload each controller every time when tab is pressed.
-
Hiren almost 13 yearsthnx for reply.... but i need to make like whenever tab pressed it reload whole page...
-
Colin over 8 yearsMy code already was in viewDidAppear() and it doesn't refresh when the same tab bar button was pressed. The answer seems incomplete.