複数のタブを持つウィンドウ ベースの iPhone アプリケーションと、これらすべてのタブに表示されるナビゲーション バー コントローラーがあります。これは天気/気候アプリなので、ユーザーに最初に都市を選択してもらい、次にその都市の各タブに天気情報が表示されるようにします (ナビゲーション バーを使用して任意のタブから選択した都市に戻ることができます。私はこれに従いましたガイド: http://www.youtube.com/watch?v=LBnPfAtswgwしかし、同じ設定でさらにタブを追加したので、現在のタブを取得し、次のようにアプリ デリゲートをインスタンス化します。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger currTab;
AppDelegate_iPhone *delegate = [[UIApplication sharedApplication] delegate];
currTab = delegate.rootTabController.selectedIndex;
...
それは正常に動作し、viewDidAppear で呼び出されたときに正しい選択されたタブを返します。次に、対応するビュー (この場合は UIForecastViewController) にプッシュするための私のコードは次のようになります。
if (currTab == 0) {
if (self.forecastViewController == nil) {
UIForecastViewController *chosenCity = [[UIForecastViewController alloc] initWithNibName:@"UIForecastViewController" bundle:nil];
// note forecastViewController is a variable, not the class
self.forecastViewController = chosenCity;
[chosenCity release];
}
forecastViewController.title = [NSString stringWithFormat:@"%@ Forecast",[cityArray objectAtIndex:row]];
[delegate.navController pushViewController:forecastViewController animated:YES];
}
他のすべては正常に機能しますが、pushViewController は何もしません。私は解決策を無益に検索しました。わずかに似た例がありますが、アプリデリゲートを使用したり、結果を提供したりするものはありません。うまくいけば、私が持つべきすべてのことを述べました。どんな助けやアドバイスも大歓迎です! よろしく。