Can I use a single prototype cell in multiple tableViews?

后端 未结 5 1939

I am having two different tableviews in two different controller. But the cells, that I need to display in them, look identical. I have created a prototype cell in one tableView

5条回答
  •  春和景丽
    2021-02-05 07:14

    You can use same prototype cell in different view controllers, you just need to dequeue it from the tableview of controller in which you designed it.

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      let viewControllerInWhichCellWasDefined = tabBarController?.viewControllers?[0]   
      let cell = viewControllerInWhichCellWasDefined.tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath)
      return cell
    }
    

提交回复
热议问题