我在使用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,等等。如果您注释第七个按钮添加的行,则操作表会生成一种类似于tableView的表格,取消按钮会出现在额外一行上。在这种情况下,如果我按“one”按钮,则buttonindex变量为0,而cancelButtonIndex也是0。无法确定用户是否点击了“取消”或“one”按钮。这看起来不应该是这样的。有人持反对意见吗?感谢您的帮助。