1

I have a view controller inside a tab bar controller. When I'm "inside" the initialized view I want to be able to press the tab bar item again and redraw the view.

My tabbarcontroller is created in the AppDelegate

#AppDelegate.m
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSString *titleV = viewController.title;
    if (titleV == @"Random") {
        DetailViewController *detailViewController = [[DetailViewController alloc] init];
        [detailViewController reloadView];
    }
}

#ViewController.m
-(void)reloadView{
    [self.view setNeedsDisplay];
    NSLog(@"view updated");
}
//code
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self checkContent];
    NSLog(@"viewDidLoad");
}
//code
-(void)checkContent{
    if (theContent==NULL) {
        contentText.numberOfLines=0;
        contentText.text = randomContent;
        NSLog(@"%@", contentText.text);
    } else {
        contentText.text = theContent;
    }
}

From the log I can see that contentText.text gets updated though the visible label does not until I move to another view and then back again. I'm not sure why this isn't working. Any ideas on how to solve this are greatly appreciated.

If you need more code I'd be happy to provide it.

Cheers, Dubbelsnurr

Emil
  • 7,220
  • 17
  • 76
  • 135

1 Answers1

0

Instead of putting - tabBarController:didSelectViewController in appDelegate, I would sub-class my tabBarController and conform to UITabBarDelegate, and call - tabBarController:didSelectViewController from within that.

Here is a tutorial that implements a similar concept:

http://iosdevelopertips.com/user-interface/detect-taps-on-uitabbarcontroller-and-determining-class-type.html

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sierra Alpha
  • 3,707
  • 4
  • 23
  • 36