Reputation: 41
I Have array , i want load data to table view cell from that array . But I dont how to do. Any ideas?
Array = [{id:1,title:a,desc:abc},{id:2,title:b,desc:abc},{id:3,title:c,desc:abc}]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? TableViewCell
cell.label1.text = "Data from array"
cell.label2.text = "Data from array"
return cell!
}
based on the array.count I want display the cells
firstcell = array[0]
secondcell = array[1]
thirdcell = array[2]
this is what i want to do
Upvotes: 1
Views: 940
Reputation: 87635
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
asks for a specific cell at indexPath
, this value contains row
and section
By default table view has single section so you only need row
:
cell.label1.text = array[indexPath.row]
Upvotes: 1