-
Notifications
You must be signed in to change notification settings - Fork 41
/
WBMultiSelectGroupsViewController.m
95 lines (71 loc) · 3.13 KB
/
WBMultiSelectGroupsViewController.m
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
#import "WBMultiSelectGroupsViewController.h"
#import "xia0WeChat.h"
#import <objc/objc-runtime.h>
@interface WBMultiSelectGroupsViewController () <ContactSelectViewDelegate>
@property (strong, nonatomic) ContactSelectView *selectView;
@property (strong, nonatomic) NSArray *blackList;
@end
@implementation WBMultiSelectGroupsViewController
- (instancetype)initWithBlackList:(NSArray *)blackList {
if (self = [super initWithNibName:nil bundle:nil]) {
_blackList = blackList;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initTitleArea];
[self initSelectView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
MMServiceCenter *serviceCenter = [objc_getClass("MMServiceCenter") defaultCenter];
CContactMgr *contactMgr = [serviceCenter getService:objc_getClass("CContactMgr")];
for (NSString *contactName in self.blackList) {
CContact *contact = [contactMgr getContactByName:contactName];
[self.selectView addSelect:contact];
}
}
- (void)initTitleArea {
self.navigationItem.leftBarButtonItem = [objc_getClass("MMUICommonUtil") getBarButtonWithTitle:@"取消" target:self action:@selector(onCancel:) style:0];
self.navigationItem.rightBarButtonItem = [self rightBarButtonWithSelectCount:self.blackList.count];
self.title = @"黑名单";
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0]}];
}
- (UIBarButtonItem *)rightBarButtonWithSelectCount:(unsigned long)selectCount {
UIBarButtonItem *barButtonItem;
if (selectCount == 0) {
barButtonItem = [objc_getClass("MMUICommonUtil") getBarButtonWithTitle:@"确定" target:self action:@selector(onDone:) style:2];
} else {
NSString *title = [NSString stringWithFormat:@"确定(%lu)", selectCount];
barButtonItem = [objc_getClass("MMUICommonUtil") getBarButtonWithTitle:title target:self action:@selector(onDone:) style:4];
}
return barButtonItem;
}
- (void)onCancel:(UIBarButtonItem *)item {
if ([self.delegate respondsToSelector:@selector(onMultiSelectGroupCancel)]) {
[self.delegate onMultiSelectGroupCancel];
}
}
- (void)onDone:(UIBarButtonItem *)item {
if ([self.delegate respondsToSelector:@selector(onMultiSelectGroupReturn:)]) {
NSArray *blacklist = [[self.selectView.m_dicMultiSelect allKeys] copy];
[self.delegate onMultiSelectGroupReturn:blacklist];
}
}
- (void)initSelectView {
self.selectView = [[objc_getClass("ContactSelectView") alloc] initWithFrame:[UIScreen mainScreen].bounds delegate:self];
self.selectView.m_uiGroupScene = 5;
self.selectView.m_bMultiSelect = YES;
[self.selectView initData:5];
[self.selectView initView];
[self.view addSubview:self.selectView];
}
#pragma mark - ContactSelectViewDelegate
- (void)onSelectContact:(CContact *)arg1 {
self.navigationItem.rightBarButtonItem = [self rightBarButtonWithSelectCount:[self getTotalSelectCount]];
}
- (unsigned long)getTotalSelectCount {
return (unsigned long)[self.selectView.m_dicMultiSelect count];
}
@end