【发布时间】:2020-01-31 12:49:24
【问题描述】:
我在 tableview 中有两个 Xib,一个是单元格自定义 UITableViewCell Xib,第二个是 UIView 自定义视图 xib(即footerView)。单击日期单元格时,它会显示我的约会列表。 (附上图片供参考)。
我从SQLite 获取数据,然后将记录附加到模型。
- 问题是由于未知原因它重复了
footerView中的约会列表。首先,当它加载数据时它很好。当我移动/滚动 tableView 或返回同一页面时,它显示重复。 - 我使用
for loop在footerView中显示约会列表记录。 (在 cellForRowAt 中) - 我已经检查过了,但没有数组中没有追加重复数据模型
var downloadAppData: [DownloadDisplay] = []
如何避免在单元格 TableView 中重复页脚视图行?
减速:
var downloadAppData: [DownloadDisplay] = []
型号:
struct DownloadDisplay : Codable {
var date: Int64?
var appointments: [Appointment]?
var progress: Double?
var isFinished: Bool?
}
struct Appointment : Codable {
let appointmentHour : String?
let backgroundColorDark : String?
let backgroundColorLight : String?
let controlHour : String?
let date : String?
let id : Int?
let isProjectManual : Bool?
let projectDistrict : String?
let projectFirmName : String?
let projectName : String?
let projectType : String?
let subTitle : String?
let warmingType : String?
}
表格视图:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return downloadAppData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DownloadEntryViewCell", for: indexPath) as! DownloadEntryViewCell
let dic = downloadAppData[indexPath.row]
let content = datasource[indexPath.row]
let appDate = Date(milliseconds: dic.date ?? 0)
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "tr_TR_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
dateFormatter.dateFormat = "dd MMMM yyyy EEEE"
let convertDate = dateFormatter.string(from: appDate)
cell.fileNameLabel.text = "\(convertDate)" + " Randevuları"
var stackHeight:CGFloat = 0.0
// footer view xib.
for i in (dic.appointments)! {
let child_view = Bundle.main.loadNibNamed("FooterView", owner: self, options: nil)?.first as! FooterView
child_view.projName.text = "\(i.projectName ?? "")" + " " + "\(i.subTitle ?? "")"
cell.stackViewFooter.addArrangedSubview(child_view)
stackHeight = stackHeight + 33.0
}
if content.expanded == false {
cell.rightView.backgroundColor = ("#556f7b").toColor()
cell.fileNameLabel.textColor = ("#eceff1").toColor()
cell.progressLabel.textColor = ("#eceff1").toColor()
cell.individualProgress.frame = CGRect(x: 0, y: 69, width: 360, height: 2)
cell.individualProgress.progress = 0
cell.individualProgress.backgroundColor = ("#cfd8dc").toColor()
}
return cell
}
【问题讨论】:
标签: ios swift uitableview xib