【发布时间】:2015-03-31 20:01:27
【问题描述】:
这里的主要问题是我正在将图像加载到自定义单元格中,并且在滚动时,重用的单元格在加载新图像时会显示旧图像。
坦率地说,不会有很多单元格,所以我的第一个想法是我可以使用 tableView.dequeueReusableCellWithIdentifier 来解决问题,但是我想尝试解决的每个地方都有人质疑为什么有人会这样做,或者他们只是提供模糊的建议而没有任何例子。
在重新处理图像时没有这种滞后的情况下显示单元格的最佳方式是什么?
class FavoritesPropertyViewCell: UITableViewCell {
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
@IBOutlet weak var cellPropertyImage: UIImageView!
@IBOutlet weak var cellRoomsValue: UILabel!
@IBOutlet weak var cellSpaceValue: UILabel!
@IBOutlet weak var cellPriceRangeValue: UILabel!
@IBOutlet weak var cellCityStateZipValue: UILabel!
@IBOutlet weak var cellAddressValue: UILabel!
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
var newPropertyCell: FavoritesPropertyViewCell = tableView.dequeueReusableCellWithIdentifier("FavoritesPropertyCell", forIndexPath: indexPath) as FavoritesPropertyViewCell
//... Get image, format values ...
// Put everything in the labels.
newPropertyCell.cellRoomsValue.text = roomsValue
newPropertyCell.cellSpaceValue.text = spaceValue
newPropertyCell.cellPriceRangeValue.text = priceValue
newPropertyCell.cellAddressValue.text = addressValue
newPropertyCell.cellCityStateZipValue.text = cityStateZipValue
return newPropertyCell
}
【问题讨论】:
-
如何在不使用 tableView.dequeueReusableCellWithIdentifier 的情况下使用它?