gpt4 book ai didi

ios - 在 UITableView 中滚动时标签文本丢失

转载 作者:行者123 更新时间:2023-11-28 13:13:04 25 4
gpt4 key购买 nike

滚动时出现奇怪的错误

enter image description here Label text missing

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("MessageCell", forIndexPath: indexPath) as! ChatTableNewViewCell

let msgtype=CoreDataManager.read(EntityNames.ChatEntity, attributeName: "is_mobile", index: indexPath.row)

if msgtype == "Y" {
cell.lblRecivedMsg.hidden=true
cell.lblSendMsg.text=CoreDataManager.read(EntityNames.ChatEntity, attributeName: "message", index: indexPath.row)
}
else{
cell.lblSendMsg.hidden=true
cell.lblRecivedMsg.text=CoreDataManager.read(EntityNames.ChatEntity, attributeName: "message", index: indexPath.row)
}

cell.lblRecivedMsg.layer.borderColor = UIColor.blackColor().CGColor
cell.lblRecivedMsg.layer.borderWidth = 1
cell.lblRecivedMsg.layer.masksToBounds = false
cell.lblRecivedMsg.layer.cornerRadius = 8
cell.lblRecivedMsg.clipsToBounds = true

cell.lblSendMsg.layer.borderColor = UIColor.blackColor().CGColor
cell.lblSendMsg.layer.borderWidth = 1
cell.lblSendMsg.layer.masksToBounds = false
cell.lblSendMsg.layer.cornerRadius = 8
cell.lblSendMsg.clipsToBounds = true

// Configure the cell...
cell.backgroundColor = UIColor.clearColor()
println(indexPath.row)
return cell
}

这在模拟器和 iPad 中都会发生,而且它并不总是只在我们快速滚动或滚动几次时发生。这真的很烦人:(。请帮忙

最佳答案

从您的代码看来您没有正确重置单元格。

当您设置文本时,您应该为该 TextView 将 hidden 设置为 false。

由于单元格被重复使用,您可以获得一个之前设置为隐藏的单元格。这就是它有时会丢失的原因。

if msgtype == "Y" {
cell.lblRecivedMsg.hidden=true
cell.lblSendMsg.hidden=false
cell.lblSendMsg.text=CoreDataManager.read(EntityNames.ChatEntity, attributeName: "message", index: indexPath.row)
}
else{
cell.lblSendMsg.hidden=true
cell.lblRecivedMsg.hidden=false
cell.lblRecivedMsg.text=CoreDataManager.read(EntityNames.ChatEntity, attributeName: "message", index: indexPath.row)
}

关于ios - 在 UITableView 中滚动时标签文本丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30546627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com