我有一个通用应用程序,可以在操作表中显示按钮。
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 上显示上述弹出窗口并更改方向然后点击其中一个按钮,它会在我想要显示另一个弹出窗口的那个按钮方法中崩溃,说
-[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。