2011-04-27 193 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