views:

38

answers:

1

Hi all, I have a window based iPhone application with multiple tabs and a navigation bar controller which appears on all these tabs. It's a weather/climate app, so I want the user to first choose a city, then be presented with weather info in each tab for that city (they can go back to the city select from any tab using the navigation bar. I followed this guide: http://www.youtube.com/watch?v=LBnPfAtswgw but added more tabs with the same settings. So I get the current tab and instantiate the app delegate like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSUInteger currTab;
AppDelegate_iPhone *delegate = [[UIApplication sharedApplication] delegate];
currTab = delegate.rootTabController.selectedIndex;
...

That works fine, returns correct selected tab when called in viewDidAppear. Then my code for pushing to the corresponding view (in this case, UIForecastViewController) like so:

if (currTab == 0) {
    if (self.forecastViewController == nil) {
        UIForecastViewController *chosenCity = [[UIForecastViewController alloc] initWithNibName:@"UIForecastViewController" bundle:nil];
                   // note forecastViewController is a variable, not the class
        self.forecastViewController = chosenCity;
        [chosenCity release];
    }
    forecastViewController.title = [NSString stringWithFormat:@"%@ Forecast",[cityArray objectAtIndex:row]];
    [delegate.navController pushViewController:forecastViewController animated:YES];
}

Everything else works as it should, but the pushViewController does nothing. I've searched fruitlessly for a solution, there are slightly similar examples out there but none using the app delegate or giving me any results. Hopefully I've mentioned everything I should have, any help/advice will be much appreciated! Regards.

A: 

The navController property of delegate is nil. I would start by looking at the code that is supposed to be setting this.

Any reason you're not using this?

[self.navigationController pushViewController:forecastViewController animated:YES];
Robot K
Apparently because I'm silly. That works perfectly for each tab, you sir are a gentleman and a scholar. (To clarify, I was using the delegate because that's the way the tutorial did it and it was working for a single tab, but apparently broke on multiple.) Thanks very much!
Andeh