2011-04-27 218 views
2

我有一个操作表,似乎只在调用clickedButtonAtIndex委托方法时点击“是”按钮,而不是在“否”按钮上......这里是代码:UIActionSheet委托方法不会被调用

self.myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Test" delegate:self 
     cancelButtonTitle:@"No" destructiveButtonTitle:@"Yes" otherButtonTitles:nil]; 
[self.myActionSheet showInView:self.view]; 
[myActionSheet release]; 

然后委托方法:

- (void)actionSheet:(UIActionSheet *)myActionSheet 
    clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 1) { 
     [self.myActionSheet dismissWithClickedButtonIndex:1 animated:YES]; 
     return; 
    } 

我在这个过程中的第一行断点没有被击中,除非我碰 “是”按钮。我改变了这个有cancelButtonTitle:nil,然后把“否”放在另一个按钮上(otherButtonTitles:@“No”,零)。一样。

任何帮助?
谢谢!

回答

5

尝试触摸No按钮的最顶部。它工作吗?

你有一个标签栏或工具栏吗?如果是这样,请尝试在标签栏或工具栏上显示操作表。 No按钮可能会被酒吧部分遮挡。

+0

OMG你是天才特里....是的,我有一个标签栏。这是一个错误?有关如何解决这个问题的任何建议? – DNewell 2011-04-27 20:58:44

+0

使用showFromTabBar。这将把该表放在正确的位置,以获得所有的接触。 – 2011-04-27 21:28:08

+0

我总是犯同样的错误:) – honcheng 2011-04-28 02:06:38

1

不,它不是一个错误..只是一个“房地产”问题。 看看从UIActionSheet头的API ......

// show a sheet animated. you can specify either a toolbar, a tab bar, a bar butto item or a plain view. We do a special animation if the sheet rises from 
// a toolbar, tab bar or bar button item and we will automatically select the correct style based on the bar style. if not from a bar, we use 
// UIActionSheetStyleDefault if automatic style set 
- (void)showFromToolbar:(UIToolbar *)view; 
- (void)showFromTabBar:(UITabBar *)view; 
- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_3_2); 
- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_3_2); 
- (void)showInView:(UIView *)view; 
+0

太好了,再次感谢! – DNewell 2011-04-27 21:13:12

相关问题