[英]Swift iOS TableView cell items disappears when scrolling
When I scroll through my tableview I see that some badges in my list disappears.当我滚动浏览我的 tableview 时,我看到我的列表中的一些徽章消失了。
My cell is set to have a custom class of CustomTableViewCell
我的单元格设置为自定义类CustomTableViewCell
CustomTableViewCell :自定义表视图单元格:
import UIKit
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var badgeIcon: AsyncImageView!
@IBOutlet weak var title: UILabel!
func configureCell(data: JSON) {
if let itemType = data["item_type"].int, itemTitle = data["item_type"].string {
title.text = itemTitle
if itemType == 1 {
badgeIcon.hidden = true
} else {
badgeIcon.hidden = false
}
}
tableview表视图
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("myCustomCell") as! CustomTableViewCell
let data = items[indexPath.row]
cell.configureCell(data)
//Dont show highlight
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
}
When my tableView first loads everything is displayed right with badgeIcon being shown/hidden where it should be, but if I scroll up/down a few times the badgeIcon will always remain hidden当我的 tableView 首次加载所有内容时,所有内容都正确显示,而badgeIcon显示/隐藏在它应该在的位置,但是如果我向上/向下滚动几次, badgeIcon将始终保持隐藏状态
Within your UITableViewCell
subclass, override prepareForReuse with:在您的UITableViewCell
子类中,使用以下命令覆盖 prepareForReuse:
badgeIcon.hidden = true
This way you can use a "clean slate" when configuring your cells upon reuse.通过这种方式,您可以在重用时配置单元格时使用“干净的石板”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.