Using a Cell Prototype from Another View Controller

I want to use the same kind of table cell in multiple storyboard scenarios. Can I prototype a cell in one of the scenes and somehow access it (i.e. dequeueReusableCellWithIdentifier) ​​in another table view controller?

+6
source share
2 answers

This is not possible, but you can copy the prototype cell from the source table to the destination inside the storyboard, and you can easily reuse it.

+4
source

You can create your prototype cell in a .xib file and import it into several subclasses of UITableViewController . Just make sure the identifier is synchronized between your links in the code and your prototype cell.

 class YourViewController: UITableViewController { func viewDidLoad() { super.viewDidLoad() let nib = UINib(nibName: "your_file_name", bundle: nil) tableView.registerNib(nib, forCellWithReuseIdentifier: "your_cell_identifier") // ... } } 

The same applies to custom prototypes of UICollectionViewCell and their use in subclasses of UICollectionView .

+1
source

Source: https://habr.com/ru/post/975503/


All Articles