-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlertControllerView.m
More file actions
96 lines (82 loc) · 3.48 KB
/
Copy pathAlertControllerView.m
File metadata and controls
96 lines (82 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// AlertControllerView.m
// UIAlertController
//
// Created by linghang on 2017/3/30.
// Copyright © 2017年 wangjian. All rights reserved.
//
#import "AlertControllerView.h"
@interface AlertControllerView ()
@end
@implementation AlertControllerView
- (id)initStyle:(UIAlertControllerStyle)actionStyle andTitle:(NSString *)title andContent:(NSString *)content andConfirm:(ConfirmBlock)confirmBLock andConfirmTitle:(NSString *)confirmTitle andCancelBlock:(CancelBlcok)cancelBlock andCancelTitle:(NSString *)cancelTitle andSheetArr:(NSArray *)sheetArr andDestructiveIndex:(NSInteger)index andClickIndexBlock:(ClickIndexBlock)clickIndexBlock{
self.confirmBlock = confirmBLock;
self.cancelBlock = cancelBlock;
if (title.length == 0) {
title = nil;
}
if (content.length == 0) {
content = nil;
}
if ([cancelTitle length] == 0) {
cancelTitle = @"取消";
}
if ([confirmTitle length] == 0) {
confirmTitle = @"确定";
}
self = [AlertControllerView alertControllerWithTitle:title message:content preferredStyle:actionStyle];
if (actionStyle == UIAlertControllerStyleAlert) {//弹出
__weak typeof (self) weakSelf = self;
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (weakSelf.confirmBlock) {
weakSelf.confirmBlock(@"ok");
}
}];
[self addAction:confirmAction];
}else{//从底部弹出
self.clickIndexBlock = clickIndexBlock;
[sheetArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//数组arr里边默认是字符串
__weak typeof (self) weakSelf = self;
UIAlertAction *tempAction = [UIAlertAction actionWithTitle:obj style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (weakSelf.clickIndexBlock) {
weakSelf.clickIndexBlock(@(idx));
}
}];
if (idx == index) {//不想传这个值,直接数组的count即可
__weak typeof (self) weakSelf = self;
tempAction = [UIAlertAction actionWithTitle:obj style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
if (weakSelf.clickIndexBlock) {
weakSelf.clickIndexBlock(@(idx));
}
}];
}
[self addAction:tempAction];
}];
}
__weak typeof (self) weakSelf = self;
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
if (weakSelf.cancelBlock) {
weakSelf.cancelBlock(@"cancell");
}
}];
[self addAction:cancelAction];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end