Copying & pasting views from storyboard into nib files containing table/collection views with prototype cells

Originator:xissburg
Number:rdar://21106023 Date Originated:26-May-2015 02:50 PM
Status:Open Resolved:
Product:Developer Tools/Xcode Product Version:Version 6.3.2 (6D2105)
Classification: Reproducible:Always
 
Suppose you have a view in a storyboard which contains a table view or a collection view which has one or more prototype cells. Then you create a nib file, copy this view from the storyboard, and paste it in the nib file. Now you have a table view or collection view containing prototype cells in a nib file, which is an unsupported configuration (because you can't add prototype cells to table views or collection views in nib files). However, you can still add and remove prototype cells in this table or collection view normally. If you connect things together (to load the view from the nib file, etc) and run the app though, it will crash with an error such as this:

2015-05-26 14:33:45.185 PrototypeCellBug[89966:5524761] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier InnerCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

That is, the prototype cell does not get registered with the table or collection view.

Steps to Reproduce:
1. In a storyboard, create a new view controller and add a table view to it.

2. Add a prototype cell to this table view.

3. Add a collection view to this prototype cell.

4. Layout the views as desired, setup constraints, etc.

5. Write the usual code to display the content in the table view. Everything should work fine. 

6. Now suppose you want to reuse this table view cell in multiple view controllers. Then you create a nib file to put this cell into so you can just use `UITableView`'s `registerNib(nib: UINib, forCellReuseIdentifier identifier: String)` method wherever you want to display this cell.

7. Select the cell in the storyboard and press ⌘+C to copy it. Open the nib file you just created and press ⌘+V to paste it there. Go back to the storyboard and delete the table view cell.

8. Now in the `viewDidLoad` method of the view controller that contains the table view, use `UITableView`'s `registerNib(nib: UINib, forCellReuseIdentifier identifier: String)` method to register the cell's nib file with your table view.

9. Run the project.

Expected Results:
It should just work. 

Actual Results:
It should crash with an error such as this:

2015-05-26 14:33:45.185 PrototypeCellBug[89966:5524761] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier InnerCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

Version:
Version 6.3.2 (6D2105)

Notes:
One possible solution is to add support to prototype cells in nib files.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!