Ios 如何在动态添加操作表按钮时获得这些按钮

Ios 如何在动态添加操作表按钮时获得这些按钮,ios,ios7,uiactionsheet,Ios,Ios7,Uiactionsheet,通常,当我向UIActionSheet静态添加按钮时,如下所示: UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Yu", @"Gi", @"Oh", nil]; ui操作表的外观将按如下方式分组,而取消按钮则是一个单独的组:

通常,当我向UIActionSheet静态添加按钮时,如下所示:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Yu", @"Gi", @"Oh", nil];
ui操作表
的外观将按如下方式分组,而
取消
按钮则是一个单独的组:

但是,由于我需要根据用户操作动态添加按钮,我发现如果我这样做:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: nil];
    [actionSheet addButtonWithTitle:@"Yu"];
    [actionSheet addButtonWithTitle:@"Gi"];
    [actionSheet addButtonWithTitle:@"Oh"]; //This is just an example, could add more or less
生成的
UIActionSheet
如下所示:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: nil];
    [actionSheet addButtonWithTitle:@"Yu"];
    [actionSheet addButtonWithTitle:@"Gi"];
    [actionSheet addButtonWithTitle:@"Oh"]; //This is just an example, could add more or less

我如何能够动态添加按钮,但仍然像静态添加按钮一样将它们分组


谢谢

您需要像其他按钮一样设置“取消”按钮:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
[actionSheet addButtonWithTitle:@"Yu"];
[actionSheet addButtonWithTitle:@"Gi"];
[actionSheet addButtonWithTitle:@"Oh"]; //This is just an example, could add more or less
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];