@@ -151,7 +151,7 @@ -(void)ym_setTableView{
151
151
_ym_tableView = [[UITableView alloc ] initWithFrame: CGRectMake (0 , CGRectGetMaxY (_ym_searchBar.frame), self .view.ym_width, self .view.ym_height - CGRectGetMaxY (_ym_searchBar.frame))];
152
152
_ym_tableView.delegate = self;
153
153
_ym_tableView.dataSource = self;
154
- _ym_tableView.tintColor = [UIColor grayColor ];
154
+ _ym_tableView.tintColor = [UIColor blackColor ];
155
155
[_ym_tableView registerClass: [YMTableViewCell class ] forCellReuseIdentifier: reuseIdentifier];
156
156
[self .view addSubview: _ym_tableView];
157
157
if ([_ym_tableView respondsToSelector: @selector (setSectionIndexColor: )]) {
@@ -286,22 +286,39 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
286
286
- (NSString *)tableView : (UITableView *)tableView titleForHeaderInSection : (NSInteger )section
287
287
{
288
288
YMCityGroupsModel *model = _ym_ctiyGroups[section];
289
- if ([model.title isEqualToString: @" 热门" ]) {
290
- return @" 中国热门城市" ;
291
- }
292
- if ([model.title isEqualToString: @" 最近" ]) {
293
- return @" 最近选择过的城市" ;
294
- }
295
- if ([model.title isEqualToString: @" 定位" ]) {
296
- return @" 定位的城市" ;
297
- }
298
289
return model.title ;
299
290
}
300
291
301
292
- (NSArray <NSString *> *)sectionIndexTitlesForTableView : (UITableView *)tableView {
302
293
return [_ym_ctiyGroups valueForKeyPath: @" title" ];
303
294
}
304
295
296
+ - (UIView *)tableView : (UITableView *)tableView viewForHeaderInSection : (NSInteger )section {
297
+ UIView *ym_view = [[UIView alloc ] init ];
298
+ ym_view.backgroundColor = [UIColor colorWithRed: 229 /255.0 green: 229 /255.0 blue: 229 /255.0 alpha: 1.0 ];
299
+ UILabel *ym_label = [[UILabel alloc ] init ];
300
+ ym_label.textAlignment = NSTextAlignmentLeft;
301
+ ym_label.textColor = [UIColor blackColor ];
302
+ ym_label.font = [UIFont systemFontOfSize: 16 ];
303
+ YMCityGroupsModel *cityGroupModel = _ym_ctiyGroups[section];
304
+ NSString *ym_title = cityGroupModel.title ;
305
+ if ([cityGroupModel.title isEqualToString: @" 热门" ]) {
306
+ ym_title = @" 中国热门城市" ;
307
+ }
308
+ if ([cityGroupModel.title isEqualToString: @" 最近" ]) {
309
+ ym_title = @" 最近选择过的城市" ;
310
+ }
311
+ if ([cityGroupModel.title isEqualToString: @" 定位" ]) {
312
+ ym_title = @" 定位的城市" ;
313
+ }
314
+ ym_label.text = ym_title;
315
+ [ym_label sizeToFit ];
316
+ ym_label.ym_x = 10 ;
317
+ ym_label.ym_y = 5 ;
318
+ [ym_view addSubview: ym_label];
319
+ return ym_view;
320
+ }
321
+
305
322
#pragma mark - 选中cell
306
323
- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath
307
324
{
@@ -352,13 +369,11 @@ -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPat
352
369
-(CGFloat )ym_setcellHeightForRowAtIndexPath : (NSIndexPath *)indexPath {
353
370
CGFloat ym_height = 44 ;
354
371
YMCityGroupsModel *cityGroupModel = _ym_ctiyGroups[indexPath.section];
372
+ CGFloat ym_w = ([UIScreen mainScreen ].bounds .size .width - 72 ) / 3 ;
373
+ CGFloat ym_h = ym_w / 3 ;
355
374
if (cityGroupModel.title .length > 1 ) {
356
375
NSInteger count = cityGroupModel.cities .count ;
357
- if (count >3 ) {
358
- ym_height = (count / 3 + (count % 3 == 0 ?0 :1 )) * 44 + 30 ;
359
- }else {
360
- ym_height = (count / 3 + (count % 3 == 0 ?0 :1 )) * 44 + 15 ;
361
- }
376
+ ym_height = (count / 3 + (count % 3 == 0 ?0 :1 )) * (ym_h + 15 ) + 15 ;
362
377
}
363
378
return ym_height;
364
379
}
0 commit comments