我在尝试向下滚动UITableView时遇到问题。该单元格是Prototype Custom单元格。我正在尝试使用Accordion方式扩展单元格。这是我实施手风琴的链接。我刚刚添加了一个Custom Cell。
http://www.cocoanetics.com/2011/03/expandingcollapsing-tableview-sections/
非常感谢。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"Celda"];
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
cell.name.text = [category objectAtIndex:indexPath.section];
}
else
{
cell.name.text = [(Local *)[filteredArray objectAtIndex:indexPath.row] nombreLocal];
}
}
else
{
cell.name.text = [category objectAtIndex:indexPath.section];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSInteger section = indexPath.section;
BOOL currentlyExpanded = [expandedSections containsIndex:section];
NSInteger rows;
NSMutableArray *tmpArray = [NSMutableArray array];
if (currentlyExpanded)
{
rows = [self tableView:tableView numberOfRowsInSection:section];
[expandedSections removeIndex:section];
}
else
{
[expandedSections addIndex:section];
rows = [self tableView:tableView numberOfRowsInSection:section];
}
for (int i=1; i<rows; i++)
{
NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i inSection:section];
[tmpArray addObject:tmpIndexPath];
}
if (currentlyExpanded)
{
[tableView deleteRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationNone];
}
else
{
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationNone];
}
}
}
}
答案 0 :(得分:0)
HelmiB我把我的代码放在这里:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([self tableView:tableView canCollapseSection:section])
{
if ([expandedSections containsIndex:section])
{
return [filteredArray count];
}
return 1;
}
return 1;
}