gpt4 book ai didi

ios - 如何添加包含新数据的临时单元格?

转载 作者:行者123 更新时间:2023-11-29 05:35:33 24 4
gpt4 key购买 nike

我正在尝试添加一个包含用户刚刚输入的数据的临时单元格。

使用下面的代码,我希望这样做,但我发现最后一个单元格的重复项被添加到其位置,我该如何修复此问题以添加当前数据?

         self.tableView.beginUpdates()
self.tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)//self.arrayOfComments.count-1
let cell = self.tableView.dequeueReusableCell(withIdentifier: "commentCell", for: IndexPath(row: 0, section: 0)) as! commentTableViewCell
self.addTemporaryComment(cell: cell)
self.tableView.endUpdates()

最佳答案

这个

  let cell = self.tableView.dequeueReusableCell(withIdentifier: "commentCell", for: IndexPath(row: 0, section: 0)) as! commentTableViewCell

将返回一个随机的不可见单元格及其内容,您需要的是从模型创建一个新对象并将其附加到表的数据源数组


arr.insert(yourObject,at:0)

关于ios - 如何添加包含新数据的临时单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57066752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com