【发布时间】:2018-04-13 08:48:19
【问题描述】:
这些是一些变量,我想在表格视图或集合视图中显示哪些数据。
let inr = ["200.0", "1200.0", "500.0", "2000.0", "2000.0", "2000.0", "2000.0", "2000.0", "3000.0", "5000.0", "1000.0", "100000.0", "100000.0"]
let reqtime = ["2018-04-11 13:54:46", "2018-04-09 16:31:42", "2018-04-09 12:26:32", "2018-04-09 12:19:40", "2018-04-09 12:19:35", "2018-04-09 12:19:23", "2018-04-09 12:09:05", "2018-04-09 12:08:25", "2018-04-09 11:38:15", "2018-04-09 11:07:59", "2018-04-09 11:03:58", "2018-04-09 10:54:55", "2018-04-09 10:45:47"]
let status = ["Request Approve", "Request Pending", "Request Pending", "Request Pending", "Request Pending", "Request Approve", "Request Pending", "Request Pending", "Request Pending", "Request Pending", "Request Pending", "Request Pending", "Request Approve"]
这是我的表格视图委托功能代码:
func numberOfSections(in tableView: UITableView) -> Int {
//print("inrvalue sec\(self.inrValues.count)")
return inr.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
//print("section p\(self.requestTimeValue[section])")
return reqtime[section]
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 44.0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableViewOutlet.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! DepositHistoryTableViewCell
let inrval = Double(inr[indexPath.section])
cell.lblINR.text = String(inrval)
cell.lblStatus.text = status[indexPath.section]
return cell
}
数据显示如下图: table view data
问题 1. 想要显示这样的数据...
Section: reqtime(row[0])
inr(row[0])
status(row[0]),
Section: reqtime(row[1])
inr(row[1])
status(row[1])
Section: reqtime(row[2])
inr(row[2])
status(row[2])
等等。
问题 2:有没有其他方法可以更好地显示这些数据,例如:any other way to data like this in swift
更改我的代码后,数据如下图所示:this is how data shown after numberofRowinSection return 1
【问题讨论】:
-
请注意,
inr、status和reqtime是同步的。它们应该在一个大数组中(带有自定义对象),而不是像这样分开。对于第二个问题:是的,您可以,您只需编写一个自定义单元格来模仿它,并调整您的数据源。 -
检查您的
numberOfRowsInSection。打印出section。我很确定它会返回 1,2,3,4... 等等。现在无法测试。返回 1 而不是section。 -
不,它只返回 inr 的第一个值和状态@Akaino
-
@Larme 你能用代码解释一下吗,这可能会有所帮助,谢谢
-
@Larme 其实我是从 api 获取这些数据,这个解释只是演示给你看
标签: ios arrays swift uitableview uicollectionview