Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype Cells in a nib instead of a storyboard

For better re-usability I want to create a table view outside of my Storyboard.

Now when I create a UITableView based ViewController with Nib in Xcode I get the default TableView in the nib file. However, I am not able in Interface Builder to add prototype cells like I am in my Storyboard.

Is it currently not possible to add prototype cells in a nib or am I missing something.

Thanks very much for any help.

like image 977
Besi Avatar asked Dec 20 '11 10:12

Besi


People also ask

How do you link a prototype cell to a storyboard?

From Storyboard: In Attribute Inspector set Reuse Identifier. Add your CustomCell class in your storyboard like mentioned by Jignesh Agola.

What is prototype cell in Swift?

A prototype cell acts a template for your cell's appearance. It includes the views you want to display and their arrangement within the content area of the cell. At runtime, the table's data source object creates actual cells from the prototypes and configures them with your app's data.

What does NIB stand for Xcode?

NIBs and XIBs are files that describe user interfaces, and are built using Interface Builder. In fact, the acronym "NIB" comes from "NeXTSTEP Interface Builder", and "XIB" from "Xcode Interface Builder".


1 Answers

iOS 5 includes a new method on UITableView: registerNib:forCellReuseIdentifier:

To use it, put a UITableViewCell in a nib. It has to be the only root object in the nib.

You can register the nib after loading your tableView, then when you call dequeueReusableCellWithIdentifier: with the cell identifier, it will pull it from the nib, just like if you had used a Storyboard prototype cell.

like image 87
Richard Venable Avatar answered Sep 20 '22 13:09

Richard Venable