ios - 在 Tableview 中对单元格进行分组、在单元格上方或下方添加文本以及空白区域
问题描述
我正在尝试实现类似于页面底部的图像。具体来说:
- 在每个单元格之间添加间距(您可以说在不同的组中。)
- 在单元格上方或下方添加文本。
- 其他地方都有空的空间,没有细胞。
我希望一切看起来都像这张图片。 (忽略文本、导航栏和单元格内的任何内容。)
我已经尝试过了,并得到了下面这张图片:
这是我尝试过的代码:
let data = [["0,0", "0,1", "0,2"], ["1,0", "1,1", "1,2"]]
let headerTitles = ["Some Data 1", "KickAss"]
// MARK: - TableView Data Source Methods
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let cellText = data[indexPath.section][indexPath.row]
cell.textLabel?.text = cellText
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section < headerTitles.count {
return headerTitles[section]
}
return nil
}
解决方案
TableView 状态本文档将帮助您了解 tableview 状态。(加载、数据、空状态)
推荐阅读
- airflow - Airflow -D 不工作,不在后台运行
- python - 从 python 调用 Fortran
- android - HashSet 中出现重复项
- php - 使用带有 PHP 的 Google API 获取日历事件时出现 404 错误
- vb.net - DataGridView 添加复选框并允许通过复选框仅选择基于变量值的记录
- pandas - Daframe 打印为 str 而不是 dict
- php - 如何在 Laravel 中上传文件
- sql - 最短和最长的城市名称
- flutter - Flutter Dio 数据对象
- c - 我们可以在linux中使用getcontext来获取另一个线程的上下文吗?