【问题标题】:sectioning and indexing uitableview切片和索引 uitableview
【发布时间】:2014-12-24 01:49:16
【问题描述】:

您认为提供按字母顺序操作的表格视图的最佳 plist 布局是什么?

【问题讨论】:

  • +1 你能举个例子解释一下吗,因为我很容易理解???
  • 我认为你是在正确的轨道上。您可以有一个包含 26 个条目的数组,每个条目都包含一个指向相应词典开头的指针。因此,您可以使用它来生成节标题,并使用字典来填充下面的内容。
  • 抱歉打扰各位了。我想确定解决方案的最简单方法是询问人们将使用什么 plist 布局,如果想要按字母顺序划分单词然后单词导致定义详细视图。然后使用它来填充表格的代码会是什么样子。非常感谢您的帮助

标签: ios objective-c uitableview dictionary


【解决方案1】:

UITableView 通过为 UITableView 设置数据源和委托来为可重用表格单元提供节标题和索引。 在您的 DataSource 类中,您可以实现功能

tableView:numberOfRowsInSection:
tableView:cellForRowAtIndexPath:

决定部分和单元格的数量。您可以定义以下两个函数来设置section的标题视图。

tableView:heightForHeaderInSection:
tableView:viewForHeaderInSection:

这些用于页脚视图:

tableView:heightForFooterInSection:
tableView:viewForFooterInSection:

顺便说一句,关于整个表格的页眉和页脚视图,使用

tableview setHeaderView|setFooterView

如果页眉/页脚只是一个字符串,请使用以下内容:

tableView:titleForHeaderInSection:
tableView:titleForFooterInSection:

【讨论】:

    【解决方案2】:

    您需要对数据进行结构化,以使各个部分清晰可见。在 JSON 格式中,您的数据可能如下所示:

    [
      {
        "section_name": "First Section",
        "section_index_name": "A",
        "section_contents": [
          "First Row",
          "Second Row",
          ... etc.
        ]
      },
      ... etc.
    ]
    

    numberOfSectionsInTableView: 是顶级数组中的字典数。 numberOfRowsInSection: 是该部分的 "section_contents" 数组中的元素数。

    使用"section_name" 作为您的titleForHeaderInSection:。编译一个包含所有 "section_index_name" 值的数组以从 sectionIndexTitlesForTableView: 返回以创建索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 2015-08-21
      • 2022-07-21
      • 2021-08-19
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多