0

アクションシート内にボタンを表示するユニバーサル アプリがあります。

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:[dataObj.preferences objectForKey:@"appts_name"], @"Reserve", nil];
[actionSheet showInView:self.view];

に自動的に変更される iPad では、UIPopoverController. これは正常に表示および動作しますが、上記のポップオーバーが表示されていて iPad で向きを変更し、ボタンの 1 つをタップすると、別のポップオーバーを表示したいボタン メソッドでクラッシュします。

-[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.

iPad を回転させずにボタンをタップすると、同じコードが正常に実行されます。

UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:addItemView];
popOver = [[UIPopoverController alloc] initWithContentViewController:navBar];
if (viewPopover) {
    if (self.view.window != nil) {
        CLS_LOG(@"Rect: %@ - View: %@", NSStringFromCGRect(rectPopover), viewPopover);
        [popOver presentPopoverFromRect:rectPopover inView:viewPopover permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
} else {
    // We should NEVER get here but just incase. I don't want the app to crash.
    CLS_LOG(@"No viewPopover or rectPopover - %@ - %@", viewPopover, NSStringFromCGRect(rectPopover));
}

CLS_LOG からのログ

-[AppointmentViewController showAppointmentAdd] line 148 $ Rect: {{341.333, 592}, {1, 1}} - View: <UIScrollView: 0xc8c5d40; frame = (1044 0; 768 872); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xc8c7780>; contentOffset: {-0, 188}>

rectPopoverそしてviewPopover合法です。デバイスを回転させたときだけ popOver がウィンドウ内にないと言ってクラッシュするのはなぜですか?

編集:向きを変更した後、新しいサイズを考慮してビューをリロードしているため、原因であることがわかりました。これはウィンドウで優先されるようです。また、UIActionSheet にのみ影響するようです。

4

1 に答える 1

0

回転後にポップオーバーを再表示しようとしましたか?

回転がいつ発生するかがわかれば ( willRotateToInterfaceOrientation:)、新しいアンカー ポイントに従ってポップオーバー コントローラーを再表示できます。

于 2012-08-16T21:11:40.833 に答える