I'm trying to get UITableViewCell object programmatically using Swift, so I wrote this code:
let cell:UITableViewCell = (UITableViewCell) UITableView.cellForRowAtIndexPath(indexPath.row)
but getting compile error as:
Cannot convert value of type '(UITableViewCell).Type' to specified type 'UITableViewCell'
Consecutive statements on a line must be separated by ';'
Instance member 'cellForRowAtIndexPath' cannot be used on type 'UITableView'; did you mean to use a value of this type instead?
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
The Swift overlay to the Foundation framework provides the IndexPath structure, which bridges to the NSIndexPath class. This means that, as an alternative to NSIndexPath , starting with Swift 3 and Xcode 8, you can use IndexPath . Note that IndexPath also conforms to Equatable protocol. Therefore, you can use == or !=
Swift version: 5.6. Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.
cellForRowAtIndexPath
is not a class method. Use the instance method instead.
let cell = tableView.cellForRowAtIndexPath(indexPath)
Swift 3:
let cell = tableView.cellForRow(at: indexPath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With