0

私はスイッチビューをやろうとしています。私の最初のビューはストーリーボードで、view2 に切り替えたいのですが、最初のビューでボタンをクリックしても問題ありません。問題は、戻ろうとすると画面が真っ暗になり、最初のビューに戻らないことです。ここで私が使用しているコード。

ViewController.h

- (IBAction)View2:(id)sender;

ViewController.m

- (IBAction)View2:(id)sender {
    View2 *second = [[View2 alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];
}

そして、ここでは、2 番目のビューから最初のビューに戻るために使用しているコードを示します。

view2.h

- (IBAction)back:(id)sender;

View2.m

- (IBAction)back:(id)sender {
    ViewController *second = [[ViewController2 alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];
}

私はある種のエラーをしていますか?

ありがとう

4

1 に答える 1

0

あなたの問題はView2.mにあります

- (IBAction)back:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

トリックを行う必要があります

AppleにはViewControllerプログラミングガイドがあります。

更新複数のViewControllerにジャンプバックする必要がある場合は、NSNotificationCenterを使用するか、ジャンプバックする必要のあるviewControllerへの参照を保持する必要があります。

私の経験では、次の行は2つのうちの1つを実行します(selfはUIViewControllerのサブクラスです)

[self dismissModalViewControllerAnimated:YES];

1)self別のView Controllerを提示した場合、上の行は、上に提示されたすべてのViewControllerを閉じます。self

2)self他のView Controllerを提示していない場合、上の行selfは前のViewControllerに戻ります。

于 2012-04-26T23:34:12.080 に答える