我有这个问题,我的原型动态 UITableViewCell 上的数据值在向上或向下滚动时被重置。
我正在检查单元格是否为 nil,正如其他线程中所建议的那样,因为单元格被重用但执行永远不会达到那个如果。
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
请问有什么帮助吗?
问候, 波利斯