I am creating an app in which I have five tabs. I need to reload each controller every time when tab is pressed.
Asked
Active
Viewed 1.7k times
7 Answers
14
Put the code you want to reload, in the view will appear or in view did appear of all the view.
All the best.

Warrior
- 39,156
- 44
- 139
- 214
-
thnx for reply.... but i need to make like whenever tab pressed it reload whole page... – Hiren May 10 '11 at 08:41
-
My code already was in viewDidAppear() and it doesn't refresh when the same tab bar button was pressed. The answer seems incomplete. – Colin Jan 08 '16 at 20:06
3
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];
}

Alex Nazarov
- 1,178
- 8
- 16
2
- (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];
}
}

KarenAnne
- 2,764
- 1
- 28
- 21
0
Swift 5
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let vc = self.viewControllers?[1] as? stepVC // ViewController That need to be loaded
vc?.viewDidLoad()
}

Akshay
- 52
- 1
- 9
0
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.

Praveen S
- 10,355
- 2
- 43
- 69
0
if you are you are using the uitableview use this
[tableview reloaddata];

Aravindhan
- 15,608
- 10
- 56
- 71
0
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.

Sandeep
- 20,908
- 7
- 66
- 106