ios - UIActionSheet 取消按钮的奇怪行为

我有一个 UIBarButtonItem 打开一个操作表,为用户提供关于做什么的选择。除非我尝试单击“取消”按钮,否则一切都按预期工作。按钮的目标似乎已从应有的位置向上移动。我只能通过单击“取消”和“确定”按钮中间的某处来激活它。

我在其他应用程序中尝试过操作表,它们运行良好,所以这不仅仅是我的大拇指。操作表在 UIViewController 中打开

- (void)showOpenOptions
{
    UIActionSheet *sheet = [[UIActionSheet alloc] 
    initWithTitle:NSLocalizedString(@"Open link in external application?", @"Open in external application")
    delegate:self
    cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel")
    destructiveButtonTitle:NSLocalizedString(@"Open Link", @"Open Link")
    otherButtonTitles:nil];

    [sheet showInView:self.view];
    [sheet release];
}

最佳答案

不要将当前 View Controller 的 View 传递给操作表,而是使用 UIActionSheetshowFromTabBar: 方法。

正确的道路
这将给出正确的可点击区域:

[actionSheet showFromTabBar:self.tabBarController.tabBar];

错误的方式
这会将可点击区域放在错误的位置(如果您使用的是标签栏或工具栏):

[actionSheet showInView:self.view];

如果您使用工具栏,请改用 showFromToolbar: 方法。您需要对工具栏的引用,很可能是 ivar

[actionSheet showFromToolbar:self.myToolbar];

我的旧答案也有效,但很hacky:

刚刚找到一个可能的答案:

01-Dec-2008 10:22 PM Tom Saxton: I looked at this bug some more, and it seems to be an issue with the tabbar.

If you call UIActionSheet's [sheet showInView:self.view] from a view controller that is a child of a UITabViewController, then the hit testing on the cancel button fails in that portion of the UIActionSheet that lies above the tabbar's view.

If you instead pass in the UITabBarController's view, then the UIActionSheet acts as expected.

NOTE: in iPhone OS 2.1 and earlier, the UIActionSheet came up from the top of the tab bar when you pass the child view, but in 2.2, it comes up from the bottom of the tab bar, and thus covers the tab view.

http://openradar.appspot.com/6410780

编辑:当我将 View 更改为标签栏的 View 时,它可以正常工作

[sheet showInView:self.parentViewController.tabBarController.view];

https://stackoverflow.com/questions/1197746/

相关文章:

objective-c - 允许与另一个 UIView 下的 UIView 交互

objective-c - "Auto Layout still required after ex

objective-c - 取消排队的 performSelector :afterDelay ca

objective-c - NSLog 覆盖描述方法中对象的内存地址

iphone - cocoa 应用程序的 info plist 中的 "bundle display

iphone - 如何在 UITableView beginUpdates/endUpdates 上

ios - 以编程方式获取导航栏的高度

ios - 如何自定义分组表格 View 单元格的背景/边框颜色?

iphone - 如何使 UIView 的 subview 居中

objective-c - 检查当前线程是否是主线程