我将一个数组(来自数据库)传递给操作表。我已经添加了取消按钮,但它没有取消。它显示超出边界的错误数组。这是我的代码:
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Chatting Apps" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
for (int i =0;i<self.arrOfAppNames.count;i++) {
[actionSheet addButtonWithTitle:[[self.arrOfAppNames objectAtIndex:i]objectAtIndex:1]];
}
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = [self.arrOfAppNames count];
[actionSheet showInView:self.view];
答案 0 :(得分:0)
使用此代码希望这可以帮助您:
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Chatting Apps" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
for (int i =0;i<self.arrOfAppNames.count;i++) {
[actionSheet addButtonWithTitle:[[self.arrOfAppNames objectAtIndex:i]objectAtIndex:1]];
}
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = (int)[self.arrOfAppNames count];
[actionSheet showInView:self.view];
答案 1 :(得分:0)
当我向操作表添加取消按钮时,这对我有用:
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;