开发者

self.title is returning (null)

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 displa开发者_如何学运维ys 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜