0

このカスタムの戻るボタンがあります:

- (IBAction)backToMenu:(id)sender {

[self.presentingViewController dismissModalViewControllerAnimated:YES]; 

}

iOS 6 シミュレーターでアプリをテストすると、dismissModalViewControllerAnimated は非推奨であると表示されます。代わりに、dismissViewControllerAnimated を使用する必要があるため、iOS 6 コードを使用して iOS 5 にフォールバックする方法

私はこれを試しました:

if([self respondsToSelector:@selector(presentingViewController:animated:completion:)])
    [self.presentingViewController dismissViewControllerAnimated:(YES) completion:nil];
else if([self respondsToSelector:@selector(presentingViewController:animated:)])
    [self.presentingViewController dismissModalViewControllerAnimated:YES];
else
    NSLog(@"Oooops, what system is this ?!!! - should never see this !");

しかし、結果がなければ、NSLog が表示され、ビューが閉じられません。ヒントはありますか?

前もって感謝します。

4

2 に答える 2

6

テストしているセレクターは、呼び出しているセレクターと同じではありません。次のことを試してください。

if([self.presentingViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
    [self.presentingViewController dismissViewControllerAnimated:(YES) completion:nil];
else if([self.presentingViewController respondsToSelector:@selector(dismissModalViewControllerAnimated:)])
    [self.presentingViewController dismissModalViewControllerAnimated:YES];
else
    NSLog(@"Oooops, what system is this ?!!! - should never see this !");

重要な違いは、呼び出しているオブジェクト(この場合は)が、そのオブジェクトで呼び出しているメソッドとself.presentingViewControllerは異なることです。後者をセレクターと呼びます。これは、ラッパー内に配置したいビットです。@selector()

于 2012-10-02T00:03:51.893 に答える
5

[自己却下ViewControllerAnimated:YESの完了:Nil]を使用してください。iOS 6 の場合

于 2012-10-12T06:46:33.557 に答える