I am trying to add some icons to right side of a tableView cell. You can imagine it like "mute" icon of WhatsApp but it does not show icons in cells.
Here is my code:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
var content = cell.defaultContentConfiguration()
let countryNames = Array(countryInfos.keys)
content.text = countryNames[indexPath.row]
cell.contentConfiguration = content
let myImage = UIImage(named:"star")
cell.imageView?.image = myImage
return cell
}
I tried like this also:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
var content = cell.defaultContentConfiguration()
let countryNames = Array(countryInfos.keys)
content.text = countryNames[indexPath.row]
cell.contentConfiguration = content
let myImage = UIImage(named:"star")
cell.imageView?.image = myImage
return cell
}
How can I make it visible and add it to the right side of a cell?
Note: star image is in the "Assets" folder as star.png
2
Answers
Register your cell:
Then use your CustomCell:
To access your CustomCell image, do:
I think you can use custom cell and use stackView for text and image:
then you have to register the cell in viewDidLoad
and use it like so: