我有这个问题,其中原型动态UITableViewCell上的数据值在向上滚动或向下滚动时被重置。UITableViewCell - 向上滚动或向下滚动时重置内容
我检查的单元格是零,因为建议在其他线程,因为单元格被重用,但执行从未击中,如果。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Currency formatter
let formatter = NSNumberFormatter()
formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle
formatter.locale = NSLocale(localeIdentifier: "el-GR")
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "MenuItemTableViewCell"
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MenuItemTableViewCell
if cell.isEqual(nil) {
cell = UITableViewCell(style: .Default, reuseIdentifier: "MenuItemTableViewCell") as! MenuItemTableViewCell
}
// Match category (section) with items from data source
let itemsPerSection = items.filter({ $0.category == self.categories[indexPath.section] })
let item = itemsPerSection[indexPath.row]
// cell data
cell.cellTitle.text = item.name + " " + formatter.stringFromNumber(item.price)!
cell.cellDescription.text = item.description
请帮忙吗?
问候, 城邦
单元格内容在屏幕上时是否重置?究竟发生了什么?这种方法看起来很好,还有什么其他方法与表视图交互? –
是的,重置发生在我向下滚动然后再次备份时。例如,我有一个自定义的步进控件,带有一个表示菜单项(食物)数量的标签。我将它设置为2,向下滚动(以便单元格不在视图中),再次向上滚动并且它是0.我在我的tableview中有多个部分,所以我也实现了titleForHeaderInSection和numberOfRowsInSection。没什么特别的。 – Polis
我之前有过这个问题。我现在使用翠鸟开源框架,它工作得很好。此外,它支持异步图像,这将使您的应用程序快很多,没有任何代码从你身边 –