12
12
#import " ProjectCount.h"
13
13
14
14
@interface PopFliterMenu ()<UITableViewDataSource,UITableViewDelegate>
15
- @property (nonatomic , strong , readwrite ) NSArray *items;
15
+ @property (nonatomic , strong ) NSMutableArray *items;
16
16
@property (nonatomic , strong ) XHRealTimeBlur *realTimeBlur;
17
17
@property (nonatomic , strong ) UITableView *tableview;
18
18
@property (nonatomic , strong ) ProjectCount *pCount;
@@ -24,7 +24,7 @@ - (id)initWithFrame:(CGRect)frame items:(NSArray *)items {
24
24
self = [super initWithFrame: frame];
25
25
if (self) {
26
26
// Initialization code
27
- self.items = @[@{@" all" :@" " },@{@" watched " :@" " },@{@" created " :@" " },@{@" joined " :@" " },@{@" stared" :@" " }];
27
+ self.items = @[@{@" all" :@" " },@{@" created " :@" " },@{@" joined " :@" " },@{@" watched " :@" " },@{@" stared" :@" " }];
28
28
self.pCount =[ProjectCount new ];
29
29
[self setup ];
30
30
}
@@ -37,8 +37,13 @@ - (void)refreshMenuDate
37
37
[[Coding_NetAPIManager sharedManager ] request_ProjectsCatergoryAndCounts_WithObj: _pCount andBlock: ^(ProjectCount *data, NSError *error) {
38
38
if (data) {
39
39
[weakSelf.pCount configWithProjects: data];
40
+ [weakSelf updateDateSource: weakSelf.pCount];
40
41
[weakSelf.tableview reloadData ];
41
42
}
43
+ if (error)
44
+ {
45
+ NSLog (@" get count error" );
46
+ }
42
47
}];
43
48
}
44
49
@@ -63,38 +68,79 @@ - (void)setup {
63
68
};
64
69
_realTimeBlur.hasTapGestureEnable = YES ;
65
70
66
-
67
71
_tableview = ({
68
72
UITableView *tableview=[[UITableView alloc ] initWithFrame: self .bounds];
69
73
tableview.backgroundColor =[UIColor clearColor ];
70
74
tableview.delegate =self;
71
75
tableview.dataSource =self;
72
76
[tableview registerClass: [UITableViewCell class ] forCellReuseIdentifier: @" UITableViewCell" ];
73
77
tableview.tableFooterView =[UIView new ];
78
+ tableview.rowHeight =50 ;
79
+ tableview.separatorStyle =UITableViewCellSeparatorStyleNone;
74
80
tableview;
75
81
});
76
82
[self addSubview: _tableview];
83
+ _tableview.contentOffset =CGPointMake (0 , 100 );
84
+
77
85
}
78
86
87
+
88
+ #pragma mark -- event & action
79
89
- (void )showMenuAtView : (UIView *)containerView {
80
90
[containerView addSubview: self ];
81
91
[_realTimeBlur showBlurViewAtView: self ];
82
92
}
83
93
94
+ - (void )dismissMenu
95
+ {
96
+ [self removeFromSuperview ];
97
+ }
98
+
99
+ // 组装cell标题
100
+ - (NSString *)formatTitleStr : (NSDictionary *)aDic
101
+ {
102
+ NSString *keyStr=[[aDic allKeys ] firstObject ];
103
+ NSMutableString *convertStr=[NSMutableString new ];
104
+ if ([keyStr isEqualToString: @" all" ]) {
105
+ [convertStr appendString: @" 全部项目" ];
106
+ }else if ([keyStr isEqualToString: @" created" ]) {
107
+ [convertStr appendString: @" 我创建的" ];
108
+ }else if ([keyStr isEqualToString: @" joined" ]) {
109
+ [convertStr appendString: @" 我参与的" ];
110
+ }else if ([keyStr isEqualToString: @" watched" ]) {
111
+ [convertStr appendString: @" 我关注的" ];
112
+ }else if ([keyStr isEqualToString: @" stared" ]) {
113
+ [convertStr appendString: @" 我收藏的" ];
114
+ }else
115
+ {
116
+ NSLog (@" -------------error type:%@ " ,keyStr);
117
+ }
118
+ if ([[aDic objectForKey: keyStr] length ]>0 ) {
119
+ [convertStr appendString: [NSString stringWithFormat: @" (%@ )" ,[aDic objectForKey: keyStr]]];
120
+ }
121
+ return [convertStr copy ];
122
+ }
123
+
124
+ // 更新数据源
125
+ -(void )updateDateSource : (ProjectCount*)pCount
126
+ {
127
+ _items = @[@{@" all" :[pCount.all stringValue ]},@{@" created" :[pCount.created stringValue ]},@{@" joined" :[pCount.joined stringValue ]},@{@" watched" :[pCount.watched stringValue ]},@{@" stared" :[pCount.stared stringValue ]}];
128
+ }
129
+
130
+
84
131
#pragma mark -- uitableviewdelegate & datasource
85
132
- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
86
133
return [_items count ];
87
134
}
88
135
89
136
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
90
137
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @" UITableViewCell" forIndexPath: indexPath];
91
-
92
- cell.textLabel .text =[[[_items objectAtIndex: indexPath.row] allKeys ] firstObject ];
138
+ cell.backgroundColor =[UIColor clearColor ];
139
+ [cell.textLabel setX: 20 ];
140
+ cell.textLabel .font =[UIFont systemFontOfSize: 15 ];
141
+ cell.textLabel .textColor =[UIColor colorWithHexString: @" 0x222222" ];
142
+ cell.textLabel .text =[self formatTitleStr: [_items objectAtIndex: indexPath.row]];
93
143
return cell;
94
144
}
95
145
96
- - (CGFloat )tableView : (UITableView *)tableView heightForRowAtIndexPath : (NSIndexPath *)indexPath {
97
- return 100 ;
98
- }
99
-
100
146
@end
0 commit comments