2011-12-05 3 views
3

ナビゲーションコントローラが正常に動作するのに問題があります。 RootViewControllerでテーブルのセルをクリックすると、次のViewControllerでは表示されません。UINavigationController - アプリケーションがターゲット上のnil View Controllerをプッシュしようとしましたが、何が欠けていますか?

エラーメッセージは、だから私は何か間違ったことをALLOC

を「アプリケーションがターゲット 上のゼロビューコントローラをプッシュしようとした、」私は推測して

を読み、私はおそらくより重要な何かが足りません私が従う本。

だから、問題は私のRootViewController.mにここに表示されます:私はそう

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

// Navigation Controller 

    RootViewController *rootViewController = [[RootViewController alloc]init]; 

    navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController]; 

    self.window.backgroundColor = [UIColor whiteColor]; 

    [self.window addSubview:navigationController.view]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

:私のAppDelegate.mで

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    UINavigationController *navigationController= [[UINavigationController alloc]init]; 

    switch ([indexPath row]) { 

     case 0: 
      [navigationController pushViewController:kundeViewCon animated:YES]; 
      break; 

     case 1: 
      [navigationController pushViewController:kalenderViewCon animated:YES]; 
      break; 

     case 2: 
      [navigationController pushViewController:wunschViewCon animated:YES]; 
      break; 
    } 
} 

私はNavigationControllerとしてRootViewControllerを設定するには、以下のことをやっています私がセル内をクリックすると、プッシュしたい他のすべてのViewControllerが得られます。私は自分の過ちや私が見逃していることを見ることができません!

多分誰かが私を助け、私にヒントを与えることができます!それは素晴らしいだろう!

+1

作成した? –

+0

これはすべて別々のクラスであり、RootViewController.hよりも作成されています – julesmummdry

+0

(at)、cozを設定することはできません。(at)が存在するように、ユーザーを命名しています!class KundeViewController; クラスKalenderViewController;クラスWunschViewController; ; インタフェースRootViewController:のUITableViewController { KundeViewController * kundeViewCon。 KalenderViewController * kalenderViewCon; WunschViewController * wunschViewCon; } end – julesmummdry

答えて

5

RootViewControllerにはすでにナビゲーションコントローラがあります。これはアプリデリゲートで作成したものです。セルを選択したときに新しいナビゲーションコントローラを作成することは意味がありません。それはおそらくより次のようになります。

また
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    switch ([indexPath row]) { 
     case 0: 
      [self.navigationController pushViewController:kundeViewCon animated:YES]; 
      break; 
     case 1: 
      [self.navigationController pushViewController:kalenderViewCon animated:YES]; 
      break; 
     case 2: 
      [self.navigationController pushViewController:wunschViewCon animated:YES]; 
      break; 
    } 
} 

を、ちょうどあなたが-pushViewController:animated:を呼び出すときにビューコントローラ(すなわちkundleViewConkalenderViewCon & wunschViewCon)がnil以外であることを確認してください。インスタンス変数やプロパティのように見えます。-viewDidLoadのように、あなたのコード内でより早くalloc/initを実行するようにしてください。

+0

ありがとうございます。私は本当にalloc /私の他のViewControllersを前にinitしませんでした。今それは動作します! – julesmummdry

1

新しいUINavigationControllerを作成する必要はありません。現在のウィンドウからコントローラを取得する必要があります。 yourControllerがあなたのインスタンス化のUIViewControllerの1(kundeViewCon、kalenderViewConまたはwunschViewCon)のGooglerのために

+0

ありがとう、それはうまく動作し、私は他のコントローラを割り当て/初期化する必要がありました。ハッピー! – julesmummdry

1

ある

[self.navigationController pushViewController:yourController animated:YES]; 

あなたがあなたのViewControllerを接続しなかった場合、これがまた起こることがあります。

"<Your Project> App Delegate"

これをしないと、コントローラが初期化されません。

また、対応する.H/.MファイルへのViewControllerのクラスの名前を変更する必要があります:オープンXIBファイル

- 「アイデンティティインスペクター」へ行く> - - >あなたのViewControllerを選択> テキストフィールド "Class"には、対応する.h/.mファイルの名前を入力します。

は、対応するエントリをクリックし解放した後、あなたのViewController enter image description here に... AppDelegateから右クリックしてドラッグすることでアプリケーション にあなたのViewControllerを接続しますkundeViewCon、kalenderViewConとwunschViewConあるenter image description here

関連する問題