Get parent-child array from coredata

旧时模样 提交于 2019-12-04 20:03:54

You start with a data model with one entity that would look something like:

Node{
  name:string
  parent<<-->Node.children
  children<-->>Node.parent
}

To use you would do a fetch for all Node objects whose parent relationship was nil. That would be your top level objects. To find the next level of objects you would just query each top level object's children attribute.

You indent rows using the UITableviewDelegate's tableView:indentationLevelForRowAtIndexPath: method. In this case you would calculate the indent for each row by taking each node object and then walking it's parent relationship recursively all the way to the top and counting the steps.

However, on iOS, indented tableviews are discouraged. If you are targeting the iPhone, an indented tableview is next to useless because you don't have enough screen area to see a useful amount of the table. Instead, use a navigation controller to display a hierarchy of tableviews each displaying a different level of the data hierarchy.

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