不要在UITableView中重用单元格

Muk*_*ore 4 iphone uitableview ios swift

let cell = tableView.dequeueReusableCellWithIdentifier("cellReuseIdentifier", forIndexPath: indexPath) as! CustomTableViewCell
Run Code Online (Sandbox Code Playgroud)

创建单元格后,我不想重复使用单元格,我希望它在内存中可用.

Max*_*ner 15

这当然是你的决定,但这是一个非常糟糕的主意.除非你的细胞少于10个,否则你tableView100%肯定不再有细胞.否则,应用程序将在内存压力下快速崩溃.

只是不要dequeue细胞.每次创建新:

let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "CellReuseIdentifier")
Run Code Online (Sandbox Code Playgroud)

不推荐,但毕竟这是你的决定.

  • `let cell = YourCustomTableViewCell(style:UITableViewCellStyle.default,复用标识符:“ YourCustomCellReuseIdentifier”)一样!YourCustomTableViewCell` (5认同)
  • 我有一个自定义单元格类。无法使用上面的代码。 (2认同)
  • @Mukul更多然后:`让单元格= UITableViewCell(样式:UITableViewCellStyle.default,reuseIdentifier:“ CellReuseIdentifier”)为!CustomTableViewCell` (2认同)
  • 上面的方法总是返回 nil 对象 (2认同)
  • 少于10个细胞?严重地?您可能拥有 1000 个单元而不会出现性能问题。您曾经在您的设备上玩过游戏吗? (2认同)