大家好,我的数据需要一个可扩展的表格 View , 是否可以在 tableView 中这样创建。在我的数据中,每个数据都有不同的 Childs,下面是我的数据
-A1
-A1.1
-A1.1.1
A1.1.1.1
+B1
+C1
+D1
----------------------
+A1
-B1
+B1.1
+C1
+D1
-----------------------
+A1
+B1
+C1
-D1
+D1.1
-D1.2
+D1.2.1
+D1.2.2
+D1.3
先帮帮我谢谢
最佳答案
试试这个:-
NSMutableIndexSet *expandedSections;
@property (strong, nonatomic) NSIndexPath *expandedIndexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
return 100;
}
else
{
return 30;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
[tableView beginUpdates];
self.expandedIndexPath = nil;
[tableView endUpdates];
}
else{
self.expandedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
[tableView beginUpdates];
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
self.expandedIndexPath = indexPath;
} else {
self.expandedIndexPath = nil;
}
[tableView endUpdates];
}
}
关于ios - 如何在 ios 中创建类似树结构的可扩展 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219982/