旋转时UIPopover崩溃

时间:2012-08-16 20:43:46

标签: ios ipad uipopovercontroller

我有一个通用应用程序,可以在动作表中显示按钮。

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

在自动更改为UIPopoverController的iPad上。这显示并且行为正常,但是如果我显示上面的弹出框并在iPad上更改方向然后点击其中一个按钮,它会在那个按钮方法中崩溃,我想要显示另一个弹出框,说

-[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}>

rectPopoverviewPopover是合法的。为什么popOver崩溃说它不在窗口中,只有当我旋转设备时?

编辑: 我发现它是由于方向改变后引起的,我正在重新加载视图以考虑新的大小。看来这在窗口中优先。它似乎也只影响UIActionSheet。

1 个答案:

答案 0 :(得分:0)

您是否尝试过旋转后尝试重新显示弹出窗口?

您知道旋转何时发生(willRotateToInterfaceOrientation:),然后您可以根据它的新锚点重新显示弹出控制器。