加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 如何引用cellForRowAtIndexPath之外的单元格

发布时间:2020-12-14 17:17:44 所属栏目:百科 来源:网络整理
导读:我正在尝试更新外部单元格中的标签 override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) - UITableViewCell 通过使用 let cell = tableView.dequeueReusableCellWithIdentifier("cell",forIndexPath: indexPath)
我正在尝试更新外部单元格中的标签

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

通过使用

let cell = tableView.dequeueReusableCellWithIdentifier("cell",forIndexPath: indexPath) as! Cell

在另一个功能.但是,我一直在收到错误.因此,我试图通过使用let cell = Cell()来引用单元格,但是我意外地发现错误为nil.最后,我试过了

let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! Cell

但不会返回错误,但标签cell.time.text未更新.

解决方法

Swift 3.0&斯威夫特4

let indexPath = IndexPath(row: 0,section: 0)
let cell = tableView.cellForRow(at: indexPath)

斯威夫特2.3

let indexPath = NSIndexPath(forRow: 0,inSection: 0)
let cell = tableView.cellForRowAtIndexPath(indexPath)

注意: – 在上述方法的帮助下,你只能得到tableView的可见单元格,除了单元格为零

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读