Skip to content

Commit 639c165

Browse files
committed
数据筛选---数据绑定~
1 parent 6d1531d commit 639c165

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

Coding_iOS/Views/PopFliterMenu.m

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#import "ProjectCount.h"
1313

1414
@interface PopFliterMenu()<UITableViewDataSource,UITableViewDelegate>
15-
@property (nonatomic, strong, readwrite) NSArray *items;
15+
@property (nonatomic, strong) NSMutableArray *items;
1616
@property (nonatomic, strong) XHRealTimeBlur *realTimeBlur;
1717
@property (nonatomic, strong) UITableView *tableview;
1818
@property (nonatomic, strong) ProjectCount *pCount;
@@ -24,7 +24,7 @@ - (id)initWithFrame:(CGRect)frame items:(NSArray *)items {
2424
self = [super initWithFrame:frame];
2525
if (self) {
2626
// Initialization code
27-
self.items = @[@{@"all":@""},@{@"watched":@""},@{@"created":@""},@{@"joined":@""},@{@"stared":@""}];
27+
self.items = @[@{@"all":@""},@{@"created":@""},@{@"joined":@""},@{@"watched":@""},@{@"stared":@""}];
2828
self.pCount=[ProjectCount new];
2929
[self setup];
3030
}
@@ -37,8 +37,13 @@ - (void)refreshMenuDate
3737
[[Coding_NetAPIManager sharedManager] request_ProjectsCatergoryAndCounts_WithObj:_pCount andBlock:^(ProjectCount *data, NSError *error) {
3838
if (data) {
3939
[weakSelf.pCount configWithProjects:data];
40+
[weakSelf updateDateSource:weakSelf.pCount];
4041
[weakSelf.tableview reloadData];
4142
}
43+
if(error)
44+
{
45+
NSLog(@"get count error");
46+
}
4247
}];
4348
}
4449

@@ -63,38 +68,79 @@ - (void)setup {
6368
};
6469
_realTimeBlur.hasTapGestureEnable = YES;
6570

66-
6771
_tableview = ({
6872
UITableView *tableview=[[UITableView alloc] initWithFrame:self.bounds];
6973
tableview.backgroundColor=[UIColor clearColor];
7074
tableview.delegate=self;
7175
tableview.dataSource=self;
7276
[tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
7377
tableview.tableFooterView=[UIView new];
78+
tableview.rowHeight=50;
79+
tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
7480
tableview;
7581
});
7682
[self addSubview:_tableview];
83+
_tableview.contentOffset=CGPointMake(0, 100);
84+
7785
}
7886

87+
88+
#pragma mark -- event & action
7989
- (void)showMenuAtView:(UIView *)containerView {
8090
[containerView addSubview:self];
8191
[_realTimeBlur showBlurViewAtView:self];
8292
}
8393

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+
84131
#pragma mark -- uitableviewdelegate & datasource
85132
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
86133
return [_items count];
87134
}
88135

89136
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
90137
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]];
93143
return cell;
94144
}
95145

96-
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
97-
return 100;
98-
}
99-
100146
@end

0 commit comments

Comments
 (0)