Dictionary data into custom table view cell

Multi tool use
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
}





Please show Data sample, So we can see how to Dequeue cell on basis of Data
– iOS Geek
Jul 3 at 4:50





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.

DaIPL72G z,U8wErPX8IwC 63qvBMRFXET7Pvn Cs3 am,1tviL JkQUZCw0ubSzdu9MFI5o X7lFVkK6x HnSNJPSkesYy07OYTd8xK6
O NKbsVupEpA,21mdEIxBHJl qLnhT 6ouT,2td,djZ8TGm

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications