UIActionSheet从子视图控制器显示iPad崩溃

我很抱歉,如果这已被问,但我似乎无法find任何地方。 我甚至在一个演示项目中重新创build了我的问题,以防你想亲眼看到它,尽pipe我不知道应该在哪里发布。

我有一个xibless基于UINavigationController的应用程序。 我的一些子ViewControllers在顶部右侧有一个button,然后显示一个UIActionSheet。 我的应用程序专为iPhone和iPaddevise,所以当我准备好显示UIActionSheet时:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"%@ Menu", [self title]] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Email", @"Print", nil]; [actionSheet setActionSheetStyle:UIActionSheetStyleDefault]; if ([actionSheet respondsToSelector:@selector(showFromBarButtonItem:animated:)]) [actionSheet showFromBarButtonItem:[[self navigationItem] rightBarButtonItem] animated:YES]; else [actionSheet showInView:[self view]]; [actionSheet release]; 

在iPad上,我试图显示UIActionSheet附加到正确的栏button,并在iPhone上它应该从底部滑入。 所有这些都很好用。

不幸的是,如果你点击button,并在iPad上显示菜单,但点击应用程序左上angular的后退button,菜单不会消失。 相反,UINavigationController尽职尽责地popup,UIActionSheet仍然在那里。 如果你尝试点击菜单上的东西,你当然会崩溃。 如果用户在屏幕上点击了其他任何东西而不是“后退”button,则菜单会正常closures。

如果你在iPhone上试用这个testing,一切都按预期工作。 没有问题。

我的演示项目有一个AppDelegate和一个ViewController,这是关于它。 AppDelegate生成一个NSDictionary的NSDictionary,所以我有一个模型,我可以通过演示这个问题。 ViewController显示字典的所有关键字,如果相应的值是一个NSDictionary,您可以点击它来深入查看。

这是一个有趣的问题。 这是UIActionSheet类参考必须说的。

在iPad上,此方法在popup窗口中显示操作表,并将拥有该button的工具栏添加到popup窗口的直通视图列表。 因此,工具栏中的点击导致相应工具栏项目的操作方法被调用。 如果您想要在点击不同的工具栏项目时取消popup窗口,则必须在您的操作处理程序方法中实现该行为。

所以当你显示动作表时,它会自动创build一个UIPopoverController,并将包含的工具条(或导航条)设置为popup窗口的passthrough视图,从而允许触摸事件继续。 我认为最好的select是为你的动作表创build一个实例variables,如果它在-viewWillDisappear:可见,就强制它解散。

 - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (self.actionSheet.window) // If action sheet is on screen, window is non-nil [self.actionSheet dismissWithClickedButtonIndex:self.actionSheet.cancelButtonIndex animated:animated]; } 

你试过强制解雇的ActionSheet viewWillDisappear?

尝试这个:

 // In MyViewController.m - (void)viewWillDisappear:(BOOL)animated { [actionSheet dismissWithClickedButtonIndex:nil animated:animated]; } 

*崩溃听起来像一个可能的EXC_BAD_ACCESS。 由于发布版本,当您更改视图时,您可能会丢失对“actionSheet”的指针引用。 在你的.h文件中引用actionSheet并且pipe理你的发布的时间可能会很好。

*另请参阅有关closures消息的文档的文档: http : //developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html