我有一个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 传递给操作表,而应使用showFromTabBar:UIActionSheet方法。

正确的方法
这将提供正确的可点击区域:

[actionSheet showFromTabBar:self.tabBarController.tabBar];

错误的方式
这会将可点击区域放置在错误的位置(如果使用标签栏或工具栏):
[actionSheet showInView:self.view];

如果使用工具栏,请改用showFromToolbar:方法。您需要引用工具栏,最有可能是ivar
[actionSheet showFromToolbar:self.myToolbar];

我的老答案也可以,但是很hacky:

刚找到一个可能的答案:



http://openradar.appspot.com/6410780

编辑:当我将 View 更改为选项卡栏的 View 时,它可以正常工作
[sheet showInView:self.parentViewController.tabBarController.view];

09-30 12:44
查看更多