質問

Navigation Controllerを使用して、新しいビューをプッシュし、そのタイトルを動的に設定しています:

- (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フィードから作成された可変配列です。

次のビューに移動すると、正しく表示されますが、新しいviewController内でNSLogを実行しようとすると、(null)としてログに記録されます。

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

2009-10-27 11:30:20.416 myApp [50289:20b]タイトルは:(null)

Webサービスクエリを取得するためのパラメーターとしてタイトルを使用する必要があります...

何か考えはありますか

役に立ちましたか?

解決

タイトルをコントローラーの -viewDidLoad または同様のものに記録しようとしている場合、View Controllerを押してから タイトルを設定しているため失敗します。コントローラをプッシュする前にコントローラのタイトルを設定すると、うまく機能するはずです。

nilになる可能性がある他の唯一の理由は、 selectedCountry 変数がnilである場合です。直接ログに記録して確認してください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top