Reputation: 133
I'm trying to recover a cell from a TableView using the method cellForRow(at: IndexPath) but the compiler doesn't seem to like this method because it won't let me call it :S
https://i.sstatic.net/Gf23z.jpg (Can't post images yet)
Here's the snippet of the code in question:
if let i = self.data.index(of: snapshot.value as! String) {
self.data[i] = snapshot.value as! String
self.tableView.cellForRow(at: i).textLabel!.text = "Modd"
self.tableView.cellForRow(at: [IndexPath(row: i, section: 0)])!.textLabel!.text = "mod"
}
else {
print("Modified an item that wasn't in the data list")
}
How should I be calling the method if the compiler accepts neither of the two?
Upvotes: 2
Views: 8460
Reputation: 5259
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell:UITableViewCell
if let i = self.data.index(of: snapshot.value as! String) {
self.data[i] = snapshot.value as! String
cell = tableView.cellForRow(at: indexPath)!
cell.textLabel!.text = "Modd"
}
else {
print("Modified an item that wasn't in the data list")
}
return cell == nil ? UITableViewCell() : cell
}
Upvotes: 0
Reputation: 2873
Your problem with your second statement is that you add the indexPath that you create to an array.
Use the following code:
self.tableView.cellForRow(at: IndexPath(row: i, section: 0))
Upvotes: 6