1

-dismissModalViewControllerAnimated:をiPadで(iPhoneアプリとして)動作させるのに問題があります。どういうわけかそれは何もしないようです。

MainViewControllerで-presentModalViewController :animated:を呼び出し ます。その後、提示されたビューコントローラから([self dismissModalViewController]を使用して) -dismissModalViewControllerを呼び出してみました。これにより、リクエストがMainViewControllerに転送されることがわかります。また、提示されたビューコントローラー(viewControllerAboutToBePresented.delegate = self;)でデリゲートを設定してから、 [self.delegate dismissModalViewController:YES]を呼び出してみました。iPadでiPhoneアプリを実行すると、どちらのアプローチも何もしないようです。

iPadのモーダルビューコントローラーを閉じるにはどうすればよいですか?

4

2 に答える 2

1

iPhoneプロジェクトをiPadに移植したのはこれが初めてでしたが[self dismissModalViewControllerAnimated:]、それは静かに失敗していました。このプロジェクトでは、OpenGLのバックグラウンドでCocoaビューコントローラーを使用していましたが、それはそれと関係があると思いました。

締め切りが途方もなく厳しいため、何が起こっているのかを理解する時間がなかったので、現在のビューコントローラのサブビューとしてモーダルビューを追加し、完了したら削除しました。(ええ、ハックですが、それはあなたのタイムスケールです...)

于 2010-09-28T23:01:52.003 に答える
0

コメントとして投稿しますが、できません。

dismissModelViewControllerAnimatedを呼び出す必要があるメインビューコントローラーです: 。提示されたビューコントローラーで[[selfparentViewController]dismissModalViewControllerAnimated:]を呼び出すか、モーダルビューコントローラーを閉じてメインビューコントローラーにプロトコルを実装するプロトコルでメソッドを定義し、提示されたビューコントローラーのデリゲートとして設定できます。そこからメソッドを呼び出します。あなたはそれを間違った方法でやっています。それはあなたの問題を解決するかもしれないし、しないかもしれません。

更新(コードサンプルはコメントでは利用できません):

MainViewControllerには、次のようなものがあります。

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

    // In this case is inside a tableviewmethod, but it could really be an action associated with a button.

    DetailViewController *controller = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
    [controller setDelegate:self]; // The delegate is the parent and is assigned, not retained.

    // Modal presentation style is only used on iPad. On iPhone is always full screen.
    // [controller setModalPresentationStyle:UIModalPresentationFullScreen];

    [controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentModalViewController:controller animated:YES];
    [controller release]; // It will be deallocated upon dismissal.
}

-(void)dismissDetailViewControllerAndProcessData:(NSDictionary *)data {

    // Do something with the data passed.
    [self processData:data];

    // Dismiss the modalviewcontroller associated with this viewcontroller.
    [self dismissModalViewControllerAnimated:YES];
}

モーダルビューコントローラーとして表示される詳細ビューコントローラーでは、必要なのは次のようなものだけです。

-(void)actionBack:(id)sender {

    // Call the delegate method. If you just need to dimiss the controller, just
    // call
    // [[self parentViewController]dismissModalViewControllerAnimated:YES];
    // and don't even bother to set up a delegate and a delegate method.

    [delegate dismissDetailViewControllerAndProcessData:nil]; // Call the parent dismissal method.
}

ただし、アプリケーションがiPhoneで正常に実行されている場合は、iPadでもiPhoneアプリと同じように正常に実行されるはずです。

于 2010-09-28T21:33:18.683 に答える