3

この質問を数回受けて、いくつかの異なる方法を試しましたが、成功しませんでした。

私が試した最新の方法は次のとおりです。表示したいViewControllerを含めました。次に、このコードをdidReceiveRemoteNotificationメソッドに入れます。

    CarFinderViewController *pvc = [[CarFinderViewController alloc] init];
   // [self.window.rootViewController presentViewController:pvc animated:YES completion:nil];
    [(UINavigationController *)self.window.rootViewController pushViewController:pvc animated:NO];

これはうまくいきませんでした。私が抱えている問題は、多くの例が示すように、最初のビューがナビゲーションコントローラーではないことだと思います。

ここに画像の説明を入力

これは私のストーリー ボードの写真です > ユーザーを送りたい VC はカー ファインダーです (右下)

誰かが私に何が間違っているのか説明できますか?

4

2 に答える 2

5

didReceiveRemoteNotificationこのような投稿通知で例としてリモート通知を受け取ったときに、基本的に postNotification を使用できます

[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];

これでFirstViewController、この通知の FirstViewController を次のように登録できます

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNotificationReceived) name:@"pushNotification" object:nil];

そしてあなたの方法で

-(void)pushNotificationReceived{

CarFinderViewController *pvc = [[CarFinderViewController alloc] init];
[self presentViewController:pvc animated:YES completion:nil];

}

deallocメソッドの通知からオブザーバーを削除することを忘れないでください

-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
于 2013-02-28T15:53:43.583 に答える
2

最も簡単な解決策は、CarFinderViewControllerその時点で表示されている場合と表示されていない場合があるナビゲーションコントローラーにプッシュしようとするのではなく、モーダルビューとして表示することだと思います。

これ以上の矛盾を避けるためのもう 1 つの重要なポイントはCarFinderViewController、クラス メソッドを直接使用するのではなく、ストーリーボードからインスタンス化することをお勧めします。

何かのようなもの:

UIViewController * vc = self.window.rootViewController;
// You need to set the identifier from the Interface
// Builder for the following line to work
CarFinderViewController *pvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"CarFinderViewController"];
[vc presentViewController:pvc animated:YES completion:nil];
于 2013-02-28T16:27:43.747 に答える