=== 代码 ===
UIActionSheet* as = // UIActionSheet alloc one
[as addButtonWithTitle:@"Button1"];
[as addButtonWithTitle:@"Button2"];
[as addButtonWithTitle:@"Button3"]; // this button will be set destructive
[as addButtonWithTitle:@"Button4"];
[as addButtonWithTitle:@"ButtonMore1"];
[as addButtonWithTitle:@"ButtonMore2"];
[as addButtonWithTitle:@"ButtonMore3"];
as.destructiveButtonIndex = 2;
=== 错误 ===
我的应用程序在横向模式下运行,超过 5 个按钮的操作表将以全屏样式显示,因此用户可以上下滚动以找到他想要的特殊按钮。
然后破坏性按钮(“Button3”)将被提升到顶部,我猜苹果不希望人们在滚动操作表时错误地点击破坏性按钮,但这会使 buttonIndex 和 buttonTitle 的顺序错误:
NSLog(@"index = %d title = %@",buttonIndex,[actionSheet buttonTitleAtIndex:buttonIndex]);
输出不完全是它们应该是的。但如果我没有设置任何破坏性按钮,那么它会按预期工作。