【发布时间】:2019-05-05 01:55:01
【问题描述】:
假设我有一个包含每个结构 a 和 b 的数组,我目前正在使用表格视图来显示数组 a。这两个结构都包含日期。
我的意图是在同一个表视图中另外显示 struct b 的数组,并按两个数组的日期对表进行排序 - 不知道这是否可能。
此外,我希望即将到来的日期不直接显示在视图中,而仅在用户向上滚动时 - 可以说是在表格顶部。
时间线视图控制器:
extension TimelineViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return addDataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let rowData = addDataArray[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "TimelineCell") as! TimelineCell
cell.setDrivenKm(drivenKm: rowData.driven)
cell.setDate(date: rowData.date)
cell.setConsumedL(consumedL: rowData.consumedL)
cell.setPricePerLiter(pricePerLiter: rowData.pricePerLiter)
return cell
}
}
结构a:
var addDataArray: [addDataStruct] = []
func createStructArray() {
...
let addData: addDataStruct = addDataStruct(date: Date(), ...)
addDataArray.append(addData)
}
struct addDataStruct: Codable {
var ...: Int
var date: Date
var ...: Double
var ...: Double
var ...: Int
}
结构b:
var notStructArray: [not] = []
func createStructArray() {
...
let notificationData: not = not(date: datePicker.date, ...)
notStructArray.append(notificationData)
notStructArray.sort(by: { $0.date < $1.date })
}
struct not: Codable {
var ...: String
var ...: String
var date: Date
var ...: Int
var ...: Int
}
【问题讨论】:
-
不清楚你的目标是什么。您想显示结构 A 中的所有行,然后显示结构 B 中的所有行,还是要将两个数组混合在一起,全部按日期排序,然后按顺序显示所有行,而不管是哪个结构从?换句话说,例如,您想要“A A A A B B B”还是想要“A B B A B A A”?
-
@rmaddy 我希望将它们混合在一起,然后按日期排序。
标签: ios swift uitableview