gpt4 book ai didi

iphone - 展开 UITableViewstylePlain 中的 UITableView 单元格

转载 作者:技术小花猫 更新时间:2023-10-29 10:44:30 26 4
gpt4 key购买 nike

我想在单击时展开表格 View 单元格。有一个表格 View ,其中两个单元格是可扩展的,而其他单元格则不是。我需要当我点击可展开的单元格时它应该显示它下面的单元格并且再次点击它应该隐藏。下面有一张图片对此进行了定义。

enter image description here

我怎样才能实现这个功能,请上面的指导。提前致谢。

最佳答案

Here是带有可扩展 UITableView 的完整教程

这是它的代码片段。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
// only first row toggles exapand/collapse
[tableView deselectRowAtIndexPath:indexPath animated:YES];

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];
}

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if (currentlyExpanded)
{
[tableView deleteRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];

cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeDown];

}
else
{
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeUp];

}
}
}
}

如下图所示

enter image description here

Thisthis一个解决方案还可以帮助您了解如何管理 Expandable TableView

关于iphone - 展开 UITableViewstylePlain 中的 UITableView 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15109099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com