views:

290

answers:

0

I have a tab bar set up which I would like to call a refresh method from a view controller each time that view controller is tapped. However, when I try calling this method from the App Delegate it crashes on a line in the refresh method containing a string from the view controller. I figure that if I'd be able to call the shouldSelectViewController from the view controller instead of from in the App Delegate then it would work, but I couldn't figure out how to do this since the tab bar is in the App Delegate. Could anyone help me out with this?

AppDelegate.m

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    if (viewController == [tabBarController.viewControllers objectAtIndex:1]) {
        SecondViewController *secondView = [SecondViewController alloc];
        [secondView refresh];
        [secondView release];
    }
    return YES;
}

SecondViewController.m

- (void)refresh {
    NSString *key = [keys objectAtIndex:arc4random()%[keys count]];
    [textView setText:key];
    [textView setContentOffset:CGPointZero animated:NO];
    [textView flashScrollIndicators];
}