【发布时间】:2011-03-10 16:11:46
【问题描述】:
我在 iPhone (iOS 4.2) 上使用 UIActionSheet 时发现了一个奇怪的问题。考虑这段代码:
- (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 代表按钮“一”,依此类推。如果您在添加第七个按钮的行中添加注释,则操作表会生成一种表格视图,而取消按钮位于额外的一行上。如果我在这种情况下按下“一”按钮,则 buttonindex 变量为 0,但 cancelButtonIndex 也是如此。无法判断用户是否点击了“取消”或“一”按钮。这似乎不应该是这样的。有人不同意吗?感谢您的帮助。
【问题讨论】:
-
操作表上有六个按钮?真的吗?我建议使用表格作为选项...
-
如果您不应该使用它,那么拥有一个可以在滚动视图中处理 6 个以上按钮的操作表有什么意义?
-
遇到了同样的问题,显然是bug
-
令人惊讶的是,这个错误——而且它显然是一个错误——在 iOS 7.0+ 中仍然存在。
标签: iphone ios uiactionsheet