取决于单元格文本的不同单元格

时间:2018-11-01 17:37:06

标签: ios swift uitableview

我有以下情况。我正在制作一个天气应用程序,并且在单元格中显示了几天的数据。我有以下结构:

第1天

最低温度

最高温度

第2天

最低温度

最高温度

第3天

最低温度

最高温度

等等等...

我还在使用节和以下功能:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "minimumTemperature")
    cell?.textLabel?.text = "fooMinTemperature"

    return cell!
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 2
}

override func numberOfSections(in tableView: UITableView) -> Int {
    return 10
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return  // logic for getting the heading of the section
}

问题来了override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

函数一次只能返回1个单元格。因此,例如,此函数现在将被调用两次,并将最低温度相加两次。如何同时添加最低和最高温度。

1 个答案:

答案 0 :(得分:2)

假设您有一些数据数组,其中数组中的每个元素都代表一天,则可以使用该部分为正确的日期选择数据。然后,使用该行在最低或最高温度之间进行选择。

diff2

我使用的变量名显然只是示例。根据需要自行更新。

您的栏目标题可以显示日期。

相关问题