SuggestionRow
SuggestionRow copied to clipboard
How to get indexPath for the customizeTableViewCell
i want to add image for each cell in tableview of suggestion-row i can add a single image by calling cell.imageView but if i want to put different image in each cell please Help
row.cell.customizeTableViewCell = { (cell, index) in
print(row.cell.tableView?.indexPath(for: cell) ?? "not found")
print(index)
cell.imageView?.image = UIImage(named: "correct.png")
// let index = cell.ind
}
i even edited the class to insert index but for some reason it print 1 everytime
i called it in cellUpdate, cellHighlighted, basic cell setup i just get the same result everytime
i manage to get a workaround but it may fail sometime if anyone have a better option please do let me know. for now this is what i did ` row.cell.customizeTableViewCell = { (cell) in
if let text = cell.textLabel!.text {
var i = 0
for j in 0..<self.options.count {
let val = self.options[j]
if val == text {
i = j
break
}
}
cell.imageView?.image = UIImage(named: "\(i)")
}
}
`
Hi @sahibhussain.
You can use any type conforming to SuggestionValue
as the value of this row. This means you can create a class or struct containing a text and image variables and add options with this type to the row. In that case you only have to get the option for a given index and access its image.