Ios 在UITableView中折叠/展开特定单元格

Ios 在UITableView中折叠/展开特定单元格,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我目前在1个UITableView中有2个类别(猫、狗) 这是一个例子: cat和dog按钮是UITableView的一部分,它们位于页眉部分。 它们充当两个类别的分隔符 我试图实现的是,当我点击cat按钮时,cat按钮下的列表应该折叠,狗按钮应该重新调整它的位置。 当我再次单击cat按钮时,列表应展开 我目前拥有的是: NSUInteger indexes = (unsigned long)filteredList.count; for (int i = 0 ; i <= ind

我目前在1个UITableView中有2个类别(猫、狗)

这是一个例子:

cat和dog按钮是UITableView的一部分,它们位于页眉部分。 它们充当两个类别的分隔符

我试图实现的是,当我点击cat按钮时,cat按钮下的列表应该折叠,狗按钮应该重新调整它的位置。 当我再次单击cat按钮时,列表应展开

我目前拥有的是:

NSUInteger indexes = (unsigned long)filteredList.count;
    for (int i = 0 ; i <= indexes - 1 ; i++)
    {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
    [self.accountBalanceTableView cellForRowAtIndexPath:indexPath].hidden = YES;
    }
nsuiger index=(无符号长)filteredList.count;

对于(inti=0;i,有两种可能性可以这样做

  • 更改要隐藏的分区中行的高度
  • 对于要隐藏的节中的行,返回0

您可以在表中使用两个单元格(maincell、subcell),并将此代码放在indexpath行的单元格中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    if (tableView == _tblDispChapters) {

        if(indexPath.row == 0){

            TVCDispChapters *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

            //Accuracy
            int acu;
            if ([[marrParentChapters objectAtIndex:indexPath.section]valueForKey:@"acuracy"]==[NSNull null] ) {
                 NSLog(@"%@",[[marrParentChapters objectAtIndex:indexPath.section]valueForKey:@"acuracy"]);
                acu=0;
            }
            else
            {
                acu=[[[marrParentChapters objectAtIndex:indexPath.section]valueForKey:@"acuracy"] intValue];
                NSLog(@"%d",acu);
            }

            cell.lbl_acu.text=[NSString stringWithFormat:@"Accuracy %d%%",acu];
            [cell.pro_cell_chapt.layer setCornerRadius:cell.pro_cell_chapt.frame.size.height/2];
            cell.pro_cell_chapt.clipsToBounds = true;
            [cell.pro_cell_chapt setTransform:CGAffineTransformMakeScale(1.0f, 2.0f)];

            cell.pro_cell_chapt.progress =  acu/100.0;
            cell.pro_cell_chapt.trackTintColor = [UIColor colorWithHex:0xDDDDDD];
            cell.pro_cell_chapt.progressTintColor = [UIColor colorWithHex:0xEF9430];


            cell.lblChepterName.text = [[marrParentChapters objectAtIndex:indexPath.section]valueForKey:@"ChapterName"];
            [cell.btn_sel_allchptr setTag:indexPath.section];
            [cell.btn_sel_allchptr addTarget:self action:@selector(checkBoxClicked:)forControlEvents:UIControlEventTouchUpInside];

            if ([[_marrHideShowSection objectAtIndex:indexPath.section] boolValue]){
                [cell.imgArrow setImage:[UIImage imageNamed:@"up-arrow1"]];
            }else{
                [cell.imgArrow setImage:[UIImage imageNamed:@"down-arrow1"]];

            }

            if ([[_marrAllChapter objectAtIndex:indexPath.section] boolValue]){
                [cell.img_cpt_select setImage:[UIImage imageNamed:@"checkbox-selected1"]];
            }else{
                [cell.img_cpt_select setImage:[UIImage imageNamed:@"checkbox-unselected1"]];
            }
            return cell;
        }else{
            TVCDispChapters *cell = [tableView dequeueReusableCellWithIdentifier:@"sub_Cell" forIndexPath:indexPath];
            cell.lblSubChapterName.text = [[[marrSubChapters objectAtIndex:indexPath.section] objectAtIndex:indexPath.row-1]valueForKey:@"ChapterName"];

            if ([[[_marrSelectionSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row-1] boolValue])
            {
                [cell.imgSelection setImage:[UIImage imageNamed:@"checkbox-selected1"]];
            }else{
                [cell.imgSelection setImage:[UIImage imageNamed:@"checkbox-unselected1"]];
            }
            return cell;
        }
    }else{

        QuestionTypeTVC *cell1 = [tableView dequeueReusableCellWithIdentifier:@"CellQuesType" forIndexPath:indexPath];

        if ([_marrSelectedQuestionypeID containsObject:[[_marrQuestiontype objectAtIndex:indexPath.row] valueForKey:@"QuestionTypeID"]]){
            cell1.imgSelection.image = [UIImage imageNamed:@"checkbox-selected1"];
        }else{
            cell1.imgSelection.image = [UIImage imageNamed:@"checkbox-unselected1"];
        }
        cell1.lblQuesType.text=@"1";
        return cell1;
    }
}

到目前为止你所尝试的可能重复?试试这个==>@PrashantTukadiya更新了我的问题