ios - 正确重置单元内容(dequeueReusableCell)

标签 ios iphone xcode swift tableview

如您所知,如果不以某种方式重置tableViewCells,则在上下滚动后可能会错误显示。在网上搜索但没有找到满意的答案后,我想知道该怎么做。

我正在使用一个带有可重复使用的标识符的prototypeCell。标题和副标题当前存储在数组中。根据索引路径,从它们中获取特定的字符串。但是我如何以某种方式重置内容,以显示正确的字符串?目前,“不正确”的单元格显示上次初始化的单元格的标题。

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


    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! UITableViewCell

    let row = indexPath.row

    cell.textLabel?.text = cellNames[row]
    cell.detailTextLabel?.text = cellDetails[row]
return cell

感谢您的回答

最佳答案

在您的 cellForRowAtIndexPath: 委托(delegate)方法中,在返回之前重置单元格的所有已修改属性。就是这样。

关于ios - 正确重置单元内容(dequeueReusableCell),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32121972/

相关文章:

ios - 开始输入时出现的 View ,iOS

iphone - 景观中的 UIRefreshControl

ios - 悬停一个 DIV 会影响另一个 DIV : Why takes two taps on portable devices?

iphone - iPhone 中的开机事件

ios - 从 String 到 Date() 转换的日期(转换后日期不正确)swift

ios - SearchBar 加载 plist 时出现问题

ios - 如果应用程序进入后台模式,则会触发 Ondisconnect

iphone - UITableView 重命名每八个单元格

ios - 如何在 OpenGl ES Xcode 中以编程方式使用抗锯齿?

c++ - "clang: error: linker command failed with exit code 1"上 "ld: symbol(s) not found for architecture x86_64"