如何创建具有多级可展开可折叠行的UITableView? [英] How to create UITableView with multilevel expandable collapsible rows?

查看:84
本文介绍了如何创建具有多级可展开可折叠行的UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个表视图(iPad应用程序),该视图可以显示和折叠不同级别的行:

I have to create a table view (iPad app) that is able to show and collapse rows at different levels:

- Client 1
 - Category 1
  - Info 1
  - Info 2
 - Category 2
  - Info 1
  - Info 2
 - Category 3
  - Info 1
  - Info 2
- Client 2
 - Category 1
  - Info 1
  - Info 2

等等...

如果用户点击a客户行,整个与客户相关的行(该客户下的类别和信息)应展开/折叠。另一方面,如果他们点击特定类别,则该类别只能扩展/折叠。

If the user taps on a client row, the whole client related rows (Categories and infos under that client) should expand/collapse. In the other hand, if they tap on a particular Category only that category should expand/collapse.

所以我打算嵌套NSMutableDictionaries来保存我可以通过动态键(例如动态客户端名称)进行访问,但我不确定这种方法是否能真正解决实际问题(使零件可折叠)。另外,我不确定是否仅使用行并使它们看起来像标题部分还是使用实际部分,因为据我所知,我无法使子部分实现三级嵌套。

So i'm planning to have nested NSMutableDictionaries to hold data which i can access by dynamic keys (like dynamic client names) but i'm not sure this approach will actually work to resolve the actual problem (make collapsible parts). Also, I'm not sure if using only rows and make them appear like header sections or use actual sections, because as far as i know i can not make sub-sections to achieve the three level nesting.

有什么想法吗?我已经看到了带有可扩展行的项目示例,但我仍然感到困惑。

Any ideas? I've seen examples of projects with expandable rows but i'm still confused.

帮助!

推荐答案

GitHub上的 TLIndexPathTools 库非常适合这种情况。为了演示,我整理了一个简单的可折叠树查看器组件。它使用每个级别的单元来支持任何树深度。尝试运行 Outline示例项目

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.

这篇关于如何创建具有多级可展开可折叠行的UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆