我以这种方式在 iPad 上显示 UIActionSheet:
_actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose action"
delegate:(id<UIActionSheetDelegate>)self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
if (special_case) {
_actionSheet.destructiveButtonIndex = [_actionSheet addButtonWithTitle:@"Discard Action"];
}
[_actionSheet addButtonWithTitle:@"Action One"];
[_actionSheet addButtonWithTitle:@"Action Two"];
_actionSheet.cancelButtonIndex = [_actionSheet addButtonWithTitle:@"Cancel"];
[_actionSheet showFromBarButtonItem:self.myActionButton animated:YES];
虽然两者都cancelButtonIndex
可以destructiveButtonIndex
正常工作,但奇怪的是在 actionSheet:didDismissWithButtonIndex: 中我firstOtherButtonIndex
设置为-1
,这显然是错误的,因为我的Action One
按钮的索引为1
,而Action Two
索引为2
.
显然,上面的重点是仅在特殊情况下才显示破坏性按钮(否则我会在 init 调用中传递所有标题,并且可能事情会很甜蜜)。
我错过了什么?