views:

54

answers:

1

Using a navigation controller, I am pushing a new view and setting the title of it dynamically:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int countryIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *selectedCountry = [[countrysData objectAtIndex: countryIndex] objectForKey: @"title"];
scheduleState *scheduleStateViewController = [[scheduleState alloc] initWithStyle:UITableViewStyleGrouped];

[self.navigationController pushViewController:scheduleStateViewController animated:YES]; 
scheduleStateViewController.title = selectedCountry; 

[scheduleStateViewController release];

CountryData being a mutable array created from an xml feed.

Now when I go to the next view, it displays correctly, however when I try to do an NSLog inside the new viewController, it logs as (null):

NSLog(@"The title is: %@", self.navigationItem.title);

2009-10-27 11:30:20.416 myApp[50289:20b] The title is: (null)

I need to use the title as a parameter for grabbing a web service query...

Any thoughts?

+2  A: 

If you're trying to log the title in the controller's -viewDidLoad or something similar, it's failing because you're setting the title after pushing the view controller. Set the title of the controller before you push it and it should work better.

The only other reason it could be nil is if the selectedCountry variable is nil. Log that directly to make sure.

iKenndac
Excellent! Thank you very much.
rson