有人可以告诉我执行方法吗UITableView
可展开/可折叠动画sections
of UITableView
如下?
or
您必须创建自己的自定义标题行并将其作为每个部分的第一行。子类化UITableView
或者已经存在的标题会很痛苦。根据他们现在的工作方式,我不确定你是否可以轻松地从他们那里得到行动。您可以将单元格设置为看起来像标题,然后设置tableView:didSelectRowAtIndexPath
手动展开或折叠其所在的部分。
我将存储与每个部分的“扩展”值相对应的布尔值数组。那么你就可以拥有tableView:didSelectRowAtIndexPath
在每个自定义标题行上切换此值,然后重新加载该特定部分。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
///it's the first row of any section so it would be your custom section header
///put in your code to toggle your boolean value here
mybooleans[indexPath.section] = !mybooleans[indexPath.section];
///reload this section
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
}
}
然后设置numberOfRowsInSection
检查mybooleans
value ,如果该部分未展开,则返回 1;如果已展开,则返回 1+ 该部分中的项目数。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (mybooleans[section]) {
///we want the number of people plus the header cell
return [self numberOfPeopleInGroup:section] + 1;
} else {
///we just want the header cell
return 1;
}
}
此外,您还需要更新cellForRowAtIndexPath
返回任何部分中第一行的自定义标题单元格。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)