kylar13 kylar13 - 1 month ago 25
iOS Question

cellForRow(at: IndexPath) in swift 3 is acting funny in XCode 8

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

http://imgur.com/aVhpXr5 (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?

Answer

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))