【发布时间】:2011-12-06 17:39:43
【问题描述】:
如果有人问过这个问题,我深表歉意,但我似乎无法在任何地方找到它。我什至在演示项目中重新创建了我的问题,以防你们中的任何人想亲眼目睹,尽管我不知道应该在哪里发布。
我有一个基于 xibless UINavigationController 的应用程序。我的一些子 ViewController 在顶部右侧有一个按钮,然后显示 UIActionSheet。我的应用是为 iPhone 和 iPad 设计的,所以当我准备好显示 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,而在 iPhone 上,它应该从底部滑入。所有这些都非常有效。
很遗憾,如果您在 iPad 上点击按钮并显示菜单,然后点击应用左上角的后退按钮,菜单不会关闭。取而代之的是 UINavigationController 尽职尽责地弹回 UIActionSheet 仍然存在。如果您尝试点击菜单上的某些内容,您当然会崩溃。如果用户点击屏幕上的任何其他内容而不是“返回”按钮,则菜单会正确关闭。
如果您在 iPhone 上尝试此测试,一切都会按预期进行。没有问题。
我的演示项目有一个 AppDelegate 和一个 ViewController,仅此而已。 AppDelegate 构建了一个 NSDictionary 的 NSDictionary,这样我就有了一个可以递归的模型来演示这个问题。 ViewController 显示了字典的所有键,如果对应的值是 NSDictionary,您可以点击它向下钻取。
【问题讨论】:
标签: ios cocoa-touch ipad uikit uiactionsheet