Reputation: 41
Ask: I have a problem when returning its own cell in cellForRowAtIndexPath
Upvotes: 0
Views: 79
Reputation: 2340
simply return your cell
in your if statement like so :
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// get rid of the `var cell: UITableViewCell!`
if tableView == tableViewUser {
cell = tableViewUser.dequeuReusableCell(withIdentifier: "userCell", for: indexPath) as! TreeViewCell
cell.setNodeData(node: self.displayArray[indexPath.row])
return cell
}
if tableView == tableViewSearch {
cell = tableViewUser.dequeuReusableCell(withIdentifier: "searchCell", for: indexPath)
cell.textLabel.text = "123456"
return cell
}
return UITableViewCell() // dont worry, you will never go there
}
Also uncomment the register
part on your tableViewUser
didSet
Upvotes: 1