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

前端之家收集整理的这篇文章主要介绍了ios – 如何引用cellForRowAtIndexPath之外的单元格前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试更新外部单元格中的标签

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的可见单元格,除了单元格为零

猜你在找的Xcode相关文章