展开和折叠部分

Expanding And Collapsing Sections

有人可以建议我如何在 Objective C 中实现以下内容吗?

当我单击该特定部分的部分行时,单独展开。我如何知道点击了哪个部分以及如何计算该特定部分的 return 行数?

注意:我在我的部分保留了一个按钮。当我单击所有部分的行时,所有部分的行都会展开,当我再次单击一个部分时,所有部分的行都会折叠。

注意:- 我的 TableView 单元格高度是 126,但是当我 运行 我的应用程序时,TableCell 高度是 75(正如我在下面提到的),当我按下在 TableCell 上,TableCell 的高度会自动扩展。

参见:- int myCurrentSelection=9999; // 全局设置。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

int myrow = (int)indexPath.row;

if (myCurrentSelection == myrow) {
    myCurrentSelection = 9999;
    cell.contentView.backgroundColor = [UIColor whiteColor];
} else {
    myCurrentSelection = myrow;
    cell.contentView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
}
[tableView beginUpdates];
[tableView endUpdates];
[self.tblView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize boundingBox = [mutArrMessages [indexPath.row][@"message"] boundingRectWithSize:CGSizeMake((self.tblView.frame.size.width - 86),MAXFLOAT)
                                                                              options:NSStringDrawingUsesLineFragmentOrigin
                                                                           attributes:@{NSFontAttributeName:[UIFont helveticaNeueLightFontOfSize:17.0]}
                                                                              context:nil].size;
CGSize size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));
if ([indexPath row] == myCurrentSelection) {
    return (MAX((size.height + 46),76)) + 50;
}
return (MAX((size.height + 46),76));
}


-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
 return 76;
}