【发布时间】:2014-06-14 06:54:42
【问题描述】:
表格从“折叠”的父单元格开始(代表这个的数组是第一次传递给函数的)。每个单元格在数组中由NSDictionary 表示。每个父单元格都有一个子单元格数组,每个子单元格都有一个子单元格数组,等等。如果一个单元格没有子单元格,则字典中的“子代”key 设置为空的NSMutableArray。
这个函数的目标是获取一个NSMutableArray 代表没有扩展单元格的tableView 并递归地扩展每个单元格及其子级(想想 Reddit 上的评论线程),同时将扩展单元格相应地添加到原始数组中.它可以工作,但是由于某种原因,单元格没有正确扩展。有些扩展了有些没有,这很奇怪。有什么想法吗?
- (void)expandCells:(NSMutableArray *)comments
{
for (NSDictionary *thread in comments)
{
// recursive loop using each child in the root's child array
NSMutableArray *children = [thread objectForKey:@"children"];
if (children && [children count] > 0)
{
[self expandCells:children];
// indexPath of root of current thread
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[comments indexOfObjectIdenticalTo:thread] inSection:0];
NSUInteger count = indexPath.row + 1;
NSMutableArray *newCellIndexes = [NSMutableArray array];
for (NSDictionary *child in children)
{
//[newCellIndexes addObject:[NSIndexPath indexPathForRow:count inSection:0]];
// a copy of self.tableCells first passed to this function,
// since you cannot modify an array while iterating over it
[self.tableCells insertObject:child atIndex:count++];
}
//[self.tableView insertRowsAtIndexPaths:newCellIndexes withRowAnimation:UITableViewRowAnimationFade];
}
}
}
【问题讨论】:
标签: ios objective-c xcode uitableview nsmutablearray