你的位置:首页 > 操作系统

[操作系统]GitHub_HeadersDownCells_标题view下拉子cells


标题view下拉子cells,可以自定义标题View、子cell的内容及数量,最近会继续优化

 https://github.com/alwaysDB/HeadersDownCells.git

以下为部分代码

 1 - (void)groupHeaderViewDidClickBtnGroupTitle:(BabySettingHeaderView *)groupHeaderView { 2 //  [self.tableView reloadData]; 3   //  DDLog(@"groupHeaderView.tag%ld", groupHeaderView.tag); 4   NSIndexSet *idxSet = [NSIndexSet indexSetWithIndex:groupHeaderView.tag]; 5   [self.tableView reloadSections:idxSet withRowAnimation:UITableViewRowAnimationNone]; 6 } 7  8 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 9   return self.groups.count; 10 } 11  12 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 13   // 获取当前的组模型 14   HeaderGroup *group = self.groups[section]; 15   if (group.isVisible) { 16     return group.cellNum; 17   } 18   return 0; 19 } 20  21 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 22   switch (indexPath.section) { 23     case 0: 24       return 88; 25     case 1: 26       return 70; 27     case 2: 28       return 52; 29       break; 30        31     default: 32       return 44; 33       break; 34   } 35 } 36  37 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 38   static NSString *cellID = @"babyCareCell"; 39   UITableViewCell *babyCell = [tableView dequeueReusableCellWithIdentifier:cellID]; 40   if (babyCell == nil) { 41     babyCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; 42   } 43   for (UIView *view in babyCell.contentView.subviews) { 44     [view removeFromSuperview]; 45   } 46    47   babyCell.selectionStyle = UITableViewCellSelectionStyleNone; 48    49   switch (indexPath.section) { 50     case 0: 51       [babyCell.contentView addSubview:self.datePicker]; 52        53       [babyCell.contentView addSubview:self.dateSureBtn]; 54 //      [babyCell.contentView bringSubviewToFront:self.dateSureBtn]; 55       NSLog(@"dateSureBtn%@", NSStringFromCGRect(self.dateSureBtn.frame)); 56        57       self.datePicker.datePickerMode = UIDatePickerModeDate; 58       return babyCell; 59       break; 60     case 1: 61       [babyCell.contentView addSubview:self.textView]; 62       return babyCell; 63       break; 64     case 2: 65       [babyCell.contentView addSubview:self.textField]; 66       self.textField.borderStyle = UITextBorderStyleRoundedRect; 67       return babyCell; 68       break; 69     default: 70       return babyCell; 71       break; 72   } 73 } 74  75 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 76   HeaderGroup *group = self.groups[section]; 77   BabySettingHeaderView *headerView = [BabySettingHeaderView headerViewWithTableView:tableView]; 78   headerView.tag = section; 79   headerView.group = group; 80   headerView.delegate = self; 81   headerView.headerTitleLabel.text = nil; 82    83   CGFloat rightMargin = 50; 84   CGFloat onlineW = 150; 85   CGFloat onlineH = 60; 86   CGFloat onlineY = 0; 87   CGFloat onlineX = SCREAN_WIDTH - rightMargin - onlineW; 88    89   switch (section) { 90     case 0: 91       headerView.headerTitleLabel.text = self.titleHeaderStr1; 92        93       self.dateLab.frame = CGRectMake(onlineX, onlineY, onlineW, onlineH); 94       self.dateLab.textAlignment = NSTextAlignmentRight; 95        96       [headerView.contentView addSubview:self.dateLab]; 97        98       return headerView; 99     case 1:100       headerView.headerTitleLabel.text = self.titleHeaderStr2;101       102       self.reasonLab.frame = CGRectMake(onlineX, onlineY, onlineW, onlineH);103       self.reasonLab.textAlignment = NSTextAlignmentRight;104       105       [headerView.contentView addSubview:self.reasonLab];106       return headerView;107     case 2:108       headerView.headerTitleLabel.text = self.titleHeaderStr3;109 110       self.numberLab.frame = CGRectMake(onlineX, onlineY, onlineW, onlineH);111       self.numberLab.textAlignment = NSTextAlignmentRight;112       113       [headerView.contentView addSubview:self.numberLab];114       return headerView;115       break;116       117     default:118       return headerView;119       break;120   }121 }122 123 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {124   return 60;125 }