1; UIAlertControllerStyleAlert 的使用;
直接在block里面写事件 不用代理方法来实现了
UIAlertController * alert=[UIAlertController alertControllerWithTitle:@”性别” message:@”请选择你的性别” preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@”男” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
self.frameType=@”男”;
[self.tableView reloadData];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@”女” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
self.frameType=@”女”;
[self.tableView reloadData];
}]];
[self presentViewController:alert animated:YES completion:nil];
2:UIAlertControllerStyleActionSheet的使用
UIAlertController * alertVC =[UIAlertController alertControllerWithTitle:@”选取你的头像” message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alertVC addAction:[UIAlertAction actionWithTitle:@”相册” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentViewController:picker animated:YES completion:^{
}];
}]];
[alertVC addAction: [UIAlertAction actionWithTitle: @”取消” style: UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alertVC animated:YES completion:nil];**