通常情况下,当我按静态向UIActionSheet添加按钮时:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Yu", @"Gi", @"Oh", nil];
UIActionSheet
的外观会出现如此分组,Cancel
按钮会成为一个单独的组:
但是,由于我需要根据用户操作动态添加我的按钮,我发现如果我这样做:
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
如下所示:
我如何能够动态添加按钮,但仍然可以按静态添加按钮进行分组?
谢谢!
答案 0 :(得分:1)
您需要像其他按钮一样设置“取消”按钮:
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"];