Question

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];
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top