使用导航控制器,我正在推动一个新视图并动态设置它的标题:

- (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是一个从xml feed创建的可变数组。

现在当我进入下一个视图时,它显示正确,但是当我尝试在新的viewController中执行NSLog时,它会记录为(null):

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

2009-10-27 11:30:20.416 myApp [50289:20b]标题是:(null)

我需要使用标题作为获取Web服务查询的参数...

有什么想法吗?

有帮助吗?

解决方案

如果您尝试在控制器的 -viewDidLoad 或类似的东西中记录标题,那么它会失败,因为您在推送视图控制器之后设置了标题。在推动控制器之前设置控制器的标题,它应该更好。

唯一的另一个原因可能是nil是 selectedCountry 变量是否为nil。直接记录以确保。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top