UIAlertView和UIActionSheet 为我们提供了简便的选择模式。然而有时候我们不能确定选择框中“选项”的个数,那么就需要动态来解决这个问题,其实灰常简单~。
正常添加UIAlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@“11”,@“22”,@“33”,@“44”, nil];
alert.delegate = self;
[alert show];
动态添加UIAlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
[alert addButtonWithTitle:@"11"];
[alert addButtonWithTitle:@"22"];
[alert addButtonWithTitle:@"33"];
[alert addButtonWithTitle:@"44"];
alert.delegate = self;
[alert show];
正常添加UIActionSheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"11", nil];
actionSheet.delegate = self;
[actionSheet showInView:self.view];
动态添加UIActionSheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"11", nil];
[actionSheet addButtonWithTitle:@"22"];
[actionSheet addButtonWithTitle:@"33"];
[actionSheet addButtonWithTitle:@"44"];
actionSheet.delegate = self;
[actionSheet showInView:self.view];