What's wrong with register(_:forCellWithReuseIdentifier:) on UICollectionView?

£可爱£侵袭症+ 提交于 2019-12-05 06:58:56

There are 3 ways to register a cell (either for UITableView or UICollectionView).

  1. You can register a class. That means the cell has no nib or storyboard. No UI will be loaded and no outlets connected, only the class initializer is called automatically.

  2. You can register a UINib (that is, a xib file). In that case the cell UI is loaded from the xib and outlets are connected.

  3. You can create a prototype cell in the storyboard. In that case the cell is registered automatically for that specific UITableViewController or UICollectionViewController. The cell is not accessible in any other controller.

The options cannot be combined. If you have a cell prototype in the storyboard, you don't have to register again and if you do, you will break the storyboard connection.

You can assign Nib to Collection view cell with an identifier as follows :

self.collectionView.register(UINib(nibName: "nibName", bundle: nil), forCellWithReuseIdentifier: "cell")

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!