shr*_*d20 37 uitableview ios swift
我正在尝试使用swift以编程方式获取UITableViewCell对象,所以我编写了这段代码
let cell:UITableViewCell = (UITableViewCell) UITableView.cellForRowAtIndexPath(indexPath.row)
Run Code Online (Sandbox Code Playgroud)
但是编译错误如下:
错误图片http://www.imagesup.net/?di=8140698032514
请帮忙!
Mun*_*ndi 98
cellForRowAtIndexPath
不是一种类方法.请改用实例方法.
let cell = tableView.cellForRowAtIndexPath(indexPath)
Run Code Online (Sandbox Code Playgroud)
斯威夫特3:
let cell = tableView.cellForRow(at: indexPath)
Run Code Online (Sandbox Code Playgroud)
小智 31
你可以将它用于Swift 4
let indexPath = IndexPath(row: 0, section: 0)
let cell = tableView.cellForRow(at: indexPath)
Run Code Online (Sandbox Code Playgroud)
Swift 5 简单的解决方案
//MARK:- Collection View
let cell = yourcollectionview.cellForItem(at: indexPath) as! YourCollectionViewCell
Run Code Online (Sandbox Code Playgroud)
表格视图
let cell = tableView.cellForRow(at: indexPath) as! YourTableViewCell
Run Code Online (Sandbox Code Playgroud)
用法
let tempImage = cell.yourImageView.image!
Run Code Online (Sandbox Code Playgroud)
首先获取您想要去的行号,然后调用下面的代码。
let indexPath = IndexPath(row: rowNumber, section: 0)
let tableViewCell = YourTableView.cellForRow(at: indexPath)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
60428 次 |
最近记录: |