在iPhone上使用UIActionSheet(iOS 4.2)時,我發現了一個奇怪的問題。考慮以下代碼:使用多於6個自定義按鈕時UIActionSheet buttonIndex值有問題?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"TestSheet"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles: nil];
[actionSheet addButtonWithTitle:@"one"];
[actionSheet addButtonWithTitle:@"two"];
[actionSheet addButtonWithTitle:@"three"];
[actionSheet addButtonWithTitle:@"four"];
[actionSheet addButtonWithTitle:@"five"];
[actionSheet addButtonWithTitle:@"six"];
//uncomment next line to see the problem in action
//[actionSheet addButtonWithTitle:@"seven"];
[actionSheet showInView:window];
[actionSheet release];
return YES;
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"buttonIndex: %d, cancelButtonIndex: %d, firstOtherButtonIndex: %d",
buttonIndex,
actionSheet.cancelButtonIndex,
actionSheet.firstOtherButtonIndex);
}
如果您啓動此應用程序,則操作表的行爲與預期相同。這意味着cancelButtonIndex始終爲0,並且按鈕索引正確報告。 1用於按鈕「one」等等。如果您在添加第七個按鈕的行中註釋,則該操作表會生成一種tableview,並在額外的行上添加cancel按鈕。如果在這種情況下按下「one」按鈕,buttonindex變量是0,但cancelButtonIndex也是。無法判斷用戶是否點擊了「取消」或「一個」按鈕。這似乎不應該是這樣。有人不同意嗎?謝謝你的幫助。
動作表上的六個按鈕?真?我建議使用表的選項...... – Eimantas 2011-03-10 16:12:33
那麼如果你不應該使用它,那麼在scrollview中有一個可以處理多於6個按鈕的動作表有什麼意義? – huesforalice 2011-03-10 16:17:43
有同樣的問題,這是一個明顯的錯誤 – 2013-04-16 10:26:49