I have a table view that I want to display two different custom cells; however, it is only displaying the first custom cell and nothing else.
class messageThreadViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return finalItems.count
} else {
return finalItems2.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "message1") as! MyTableViewCellThread
cell.messagelabel?.text = finalItems[indexPath.row]
return cell
} else {
let cell2 = tableView.dequeueReusableCell(withIdentifier: "message2") as! MyTableViewCellThread2
cell2.messageLabel2?.text = finalItems2[indexPath.row]
return cell2
}
}
}
Again, it's only displaying "cell", not both "cell" and "cell2". I've done a lot of research and couldn't find someone with the same issue. Thanks for your help.
finalItems2is not empty?indexPath.sectionwithindexPath.rowin funccellforRowAt, setnumberOfRowsInSection: 2 andnumberOfSections: 1viewDidLoad()