Dictionary data into custom table view cell

Multi tool use
Dictionary data into custom table view cell
I have the Dictionay data as key value pairs. Here key is image and value is description of image. How do I insert that data into custom table view cell:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) as! CustomTableViewCell
// **How do I insert image and description data here*****
return cell
}
Mean time you can also check this answer stackoverflow.com/a/51130421/6080920
– iOS Geek
Jul 3 at 4:50
What are the properties of your
CustomTableViewCell
?– rmaddy
Jul 3 at 5:00
CustomTableViewCell
1 Answer
1
Get the keys and values from the dictionary like this.
images = dictionary.keys
descriptions = dictionary.values
In the delegate method cellForRowAt for tableView insert the image and description.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) as! CustomTableViewCell
cell.imageView = UIImageView(image: images[indexPath.row])
cell.textLabel.text = descriptions[indexPath.row]
return cell
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please show Data sample, So we can see how to Dequeue cell on basis of Data
– iOS Geek
Jul 3 at 4:50