UIActionSheet取消按钮的奇怪行为 [英] UIActionSheet cancel button strange behaviour

查看:127
本文介绍了UIActionSheet取消按钮的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIBarButtonItem打开一个操作表,为用户提供选择做什么。一切正常,除非我尝试点击取消按钮。按钮的目标似乎已从其应该在哪里移动。我只能通过点击取消和确定按钮的中间某处激活它。





我在其他应用程序的操作表中尝试过,他们工作正常,所以它不只是我的大拇指。操作表在UIViewController中打开

   - (void)showOpenOptions 
{
UIActionSheet * sheet = [@ UIActionSheet alloc]
initWithTitle:NSLocalizedString(@在外部应用程序中打开链接,@在外部应用程序中打开)
委托:self
cancelButtonTitle:NSLocalizedString ,@Cancel)
destructiveButtonTitle:NSLocalizedString(@Open Link,@Open Link)
otherButtonTitles:nil];

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


解决方案

控制器对操作表的查看,使用 UIActionSheet showFromTabBar:方法。



正确的方式

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

  [actionSheet showFromTabBar:self.tabBarController.tabBar]; 

错误方式

(如果您使用标签栏或工具栏):

  [actionSheet showInView:self.view ]; 

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

  [actionSheet showFromToolbar:self.myToolbar]; 






我的旧答案



只是发现了一个可能的答案:

2008年12月12日下午10:22 Tom Saxton:
我再看一下这个错误,它似乎是一个问题与tabbar。



如果从UITabViewController的子视图控制器调用UIActionSheet的[sheet showInView:self.view],那么取消按钮上的命中测试将失败,位于tabbar视图上方的UIActionSheet部分。



如果你改为传递UITabBarController的视图,那么UIActionSheet将如预期的那样工作。



注意:在iPhone OS 2.1和更早版本,当您传递子视图时,UIActionSheet从标签栏的顶部出现,但在2.2中,它从标签栏的底部出现,因此覆盖了标签视图。


http://openradar.appspot.com/6410780



修改:当我将视图更改为标签栏视图时,它可以正常工作

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


I have a UIBarButtonItem opening an action sheet to offer users choices about what to do. Everything works as expected unless I try to click on the "Cancel" button. The target of the button appears to have moved up from where it should be. I can only activate it by clicking somewhere in the middle of the "Cancel" and "Ok" buttons.

I've tried at action sheets in other applications and they work fine, so it's not just my big thumb. The action sheet is opening in a 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];
}

解决方案

Instead of passing the current view controller's view to the action sheet, use the showFromTabBar: method of UIActionSheet.

The Right Way
This will give the correct tappable area:

[actionSheet showFromTabBar:self.tabBarController.tabBar];

The Wrong Way
This will put the tappable area in the wrong place (if you're using a tab bar or toolbar):

[actionSheet showInView:self.view];

If you're using a toolbar, use the showFromToolbar: method instead. You'll need a reference to the toolbar, most likely an ivar

[actionSheet showFromToolbar:self.myToolbar];


My Old Answer Also works, but is hacky:

Just found a possible answer:

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

Edit: It works correctly when I change the view to be the tab bar's view

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

这篇关于UIActionSheet取消按钮的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆