How to create UITableView with multilevel expandable collapsible rows? [closed]

耗尽温柔 提交于 2019-12-03 16:53:41

The TLIndexPathTools library on GitHub is pretty well suited for this sort of thing. To demonstrate, I put together a simple collapsible tree viewer component. It supports any tree depth using cells at each level. Try running the "Outline" sample project.

The tree component is a work-in-progress, but hopefully it should be a good start.

I think nested dictionaries would be inconvenient for – tableView:cellForRowAtIndexPath:.

Here's a lazy solution:

Use a NSMutableArray and UITableView with rows disguised to look like sections. The objects in the array would each have a property called children of type NSMutableArray. When expanding a parent item, empty the children array and insert them following the parent. When collapsing, keep moving items into children until it hits an item of the same level as the parent.

Then for animation: – insertRowsAtIndexPaths:withRowAnimation: or – deleteRowsAtIndexPaths:withRowAnimation:. Either UITableViewRowAnimationTop or UITableViewRowAnimationFade would look nice.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!