2009-10-27 59 views
0

使用導航控制器,我推一個新視圖和動態地設置它的標題:self.title被返回(空)

- (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提要創建一個可變的陣列。

現在,當我去到下一個視圖,它顯示正常,但是當我嘗試做一個NSLog的新的viewController裏面,它記錄爲(空):

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

2009-10-27 11 :30:20.416對myApp [50289:20b的標題是:(空)

我需要使用標題爲抓住一個Web服務的查詢參數......

有什麼想法?

+0

你在推視圖還是視圖控制器?您無法推送視圖。 scheduleState是什麼類? – nduplessis 2009-10-27 15:44:38

回答

2

如果您嘗試在控制器的-viewDidLoad或其他類似日誌中記錄標題,則失敗,因爲您在之後設置標題,然後按下視圖控制器。在推動它之前設置控制器的標題,它應該更好。

可能爲零的唯一原因是如果selectedCountry變量爲零。記錄,直接確認。

+0

非常好!非常感謝你。 – rson 2009-10-27 15:48:11