How to reload UIViewController
12,879
The correct way to do this would be to add any VC that needs to be refreshed as an observer to a certain NSNotificationCenter notification name. Once the VC gets this message, just call a selector that calls [self setNeedsDisplay]
.
To add a VC to NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(setNeedsDisplay) name:@"ViewControllerShouldReloadNotification" object:nil];
Don't forget to call removeObserver:self
when the view controller is deallocated.
Author by
Shubham Sharma
Updated on June 04, 2022Comments
-
Shubham Sharma almost 2 years
I want to reload all the views contained in tabbar controller(UIViewController).After searching I found that I've to apply setNeedsDisplay Method but I am not able to get where should I apply it.Any other alternatives are also welcomed
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ..... ..... self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; [self customToolbar]; [self.window addSubview:tabBarController.view]; [self.window makeKeyAndVisible]; return YES; } -(void)customToolbar { //Declared view controllers and their Navigation Controller ..... //Declared tab bar items ..... tabBarController = [[GTabBar alloc] initWithTabViewControllers:viewControllersArray tabItems:tabItemsArray initialTab:1]; }
-
Gajendra K Chauhan almost 11 yearsHi Stavash..Where can I put this method? I mean "ViewWillAppear"? I am calling view cart web service when I switch tabbar. I am using UIViewController class.
-
Stavash almost 11 yearsViewWillAppear is called for every single time the view is about to be displayed - this is not only when you switch between tab bars, but also when you push and pop a controller from the navigation stack or present and dismiss a modal view. If that suits your needs then yes, otherwise you'll need to think of something else