How to add a new xib file only

Let’s say you are building a small side project. It’s really small. It only has one simple table view. You don’t really need a separate .xib view for it, so you don’t check the box when creating MyCustomTableViewCell file. Let’s say, you just have a couple of labels to display the name and the date, so you run with it.

Then you fall in love with your project, and you want to expand it. 😍 Now you need a custom .xib view for this cell, so it looks cooler!

So, how do you add just a new .xib view without creating a new file?

In Xcode menu, select File -> New -> File, or use a shortcut key: Command + N. Then select iOS -> User Interface -> Empty

Give it a name (probably the same one as your table view cell, so MyCustomTableViewCell). This will add a new .xib file to your app.

Drag a table view cell to your .xib and change its class to your custom class name. Add a Reuse Identifier.

Voila! Now throw in some labels, create IBOutlet connections from the .xib view to your custom cell class, and customize the cell however you want.

Happy coding!

Resources:

https://medium.com/@musawiralishah/creating-custom-uitableviewcell-using-nib-xib-files-in-xcode-9bee5824e722#.b3gfeec16

Like what you read? Give Ayuna Vogel a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.