操作表取消按钮不取消操作表

时间:2014-08-14 10:19:18

标签: ios objective-c uiactionsheet uiactionsheetdelegate

我将一个数组(来自数据库)传递给操作表。我已经添加了取消按钮,但它没有取消。它显示超出边界的错误数组。这是我的代码:

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];

2 个答案:

答案 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;