5

AppDelegate の Navigationcontroller に関する問題があります。次のようなストーリーボードを使用しています。

絵コンテ

プッシュ通知を使用した結果、AppDelegate ファイルに次の機能が追加されました。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//...
}

通知が届いたら、パラメーターとして ID を必要とする「詳細ビュー」コントローラーを初期化します。この ID はペイロードの一部であるため、didReceiveRemoteNotification.

私は次のことをしたいです:

DetailView *detail = [storyboard instantiateViewControllerWithIdentifier:@"detail"];

detail.conversationID = theID; 

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

この時点での私の質問は、ナビゲーション コントローラーを取得するにはどうすればよいですか? 「getNavigationControllerByIdentifier」などの関数を検索しましたが、何も見つかりませんでした。ナビゲーションバーがないため、Detail View Controller を直接インスタンス化できません。

私の言いたいことを理解していただければ幸いです。私のアプローチが完全に間違っていると思われる場合は、修正してください;o)

もう1つの小さな情報:詳細ビューコントローラーの戻るボタンがテーブルビューに戻ることは重要ではありません-「テーブルビューの読み込み」ボタンでコントローラーにリンクするだけで十分です。

ご協力ありがとう御座います!

4

2 に答える 2

8

UINavigationControllerUIViewControllerサブクラスであり、ストーリーボードで識別子を割り当てることもできます。

を使用してルート ビュー コントローラ-instantiateViewControllerWithIdentifier:を作成します。UINavigationControllerコードですべての中間コントローラーをインスタンス化し、ナビゲーション コントローラーのviewControllersプロパティを変更して、適切なナビゲーション スタックを設定する必要がある場合があります。このようにして、アプリが詳細ビューで起動すると、インターフェースを介して手動で最後まで押し込んだかのように、元に戻ることができます。

于 2012-01-10T18:48:08.310 に答える
4

rootViewControllerウィンドウオブジェクトで使用できます。

UIViewController *rootViewController = self.window.rootViewController;
// You now have in rootViewController the view with your "Hello world" label and go button.

// Get the navigation controller of this view controller with:
UINavigationController *navigationController = rootViewController.navigationController;

// You can now use it to push your next view controller:
DetailViewController *detail = [navigationController.storyboard instantiateViewControllerWithIdentifier:@"detail"];
detail.conversationID = theID; 
[navigationController pushViewController:detailViewController animated:YES];
于 2012-01-10T19:09:01.097 に答える