appzYourLife appzYourLife - 4 months ago 9
Swift Question

Same prototype cell with multiple UITableView(s)

In Storyboard I can define one (or more) prototype cell(s) to be used with a

UITableView
.

However I'd need to use the same prototype cell with multiple UITableView(s)?

Is it possible?
Thanks.

Answer

The only way to share a cell across UITableView's is to define them in an .xib as a separate file and give them a reuse identifier. Then in code register that file / corresponding class to the UITableView.

e.g. place this inside the viewDidLoad() of your tableViewController:

tableView.registerNib(UINib(nibName: "", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "")

And then you can continue on as normal inside the cellForRowAtIndexPath