Combining Storyboards and XIBs in Xcode

Posted on Nov. 12, 2013

You're zipping along prototyping your app using Interface Builder and storyboards. But now you want to reuse a scene all over the place. What do you do? Combine the power of storyboards and XIBs by mixing them!

You could segue from many different areas, but unless the view controller behaves quite similarly, you'll soon run into issues with IBOutlet and IBAction mappings. The best solution? Use a XIB for those tricky areas.

Learning iOS? Subscribe to my iOS articles, tips and tutorials.

You could also have the same Controller.h and Controller.m files, but build the scene in Interface Builder multiple times. But this is a pain to maintain and error-prone.

How do we do this? Quite simple actually. As always, a few assumptions first:

  1. We're using a UITableViewController somewhere in the storyboard.
  2. When we click on a cell of the above table, we want to segue to our custom view controller. However, don't set up any segues related to this yet.

First off, create your new view controller, making sure it subclasses UIViewController and that you tell Xcode to use a XIB. Let's call it CustomViewController. Feel free to add buttons and labels to your XIB. Connect outlets and actions as necessary.

Now head over to your main storyboard. Add an empty UIViewController onto the canvas and change the identity to CustomViewController. Now here's the key part: using the document outline1, find the View listed under Custom View Controller. Highlight it, and delete it.

And that's it! Now the storyboard will load your custom XIB whenever it segues to this view.

So what are the advantages? You can create segues back from this view to other parts of the storyboard. Granted, you'll have to call them manually, but this is a huge advantage.

Try it: control-drag from your placeholder controller in the storyboard back to the UITableViewController. Highlight the created segue, and in the Attribute Inspector, rename it to backToTable. Then in an IBAction method inside CustomViewController, call:

[self performSegueWithIdentifier:@"backToTable" sender:self];

Moreover, if all these controllers are embedded in UINavigationController, you'll get all these segues for free!

  1. That's the side bar on the left when using Interface Builder. 


Pieter E.June 6, 2014, 5:40 p.m.

Thank you for this great blog post. I tried your solution and it works excellent when using one single xib file. But adding multiple Views, based on your blog post, crashes the application every time. Do you have any idea how to solve this? Thank you in advance for your response.

silviogutierrezJune 9, 2014, 8:32 p.m.

I'm afraid I'm not sure how to address this. Thanks for reading.

BadruMarch 16, 2015, 9:59 a.m.


Alex ZakJune 23, 2015, 12:52 p.m.

Hey, I tried to follow your steps, but it seems like storyboard in not loading my VC's xib, but rather showing an empty, transparent view... did you ever encounter such a behaviour? any suggestions?

Team ExtremeJune 18, 2019, 7:12 p.m.

Get Used Motorcycles For Sale from Team X-Treme at the very best price in houston.

Kiara KeastFeb. 27, 2019, 10:34 a.m.

The chain f the consumption is filled for the occupation of the challenges. All the issues have been defend for the movement of the for all matters. The hosting is done for the authority of the parts for the humans.

star19March 7, 2019, 10:13 a.m.

I was wondering what is really on this picture, good things that it is discuss below the picture. Now I know what is the painting all about. Thanks for sharing.
Cgc admission
top agriculture college in Punjab

hijMarch 28, 2019, 11:18 a.m.

Apple products are revered for its quality, precision and great design. SRSG started its operations as Apple technology partners in the year 1997.
MacBook pro reseller in kolkata
iMac reseller delhi
ipad air reseller in bhubaneswar

dsdsdMay 6, 2019, 5:33 a.m.

Par conséquent, la manière d'éliminer efficacement les préoccupations des clients en matière de vente est une connaissance et une compétence qui doivent être maîtrisées par le vendeur. replique montre Parce que les vendeurs intelligents savent que si vous ne pouvez pas éliminer fondamentalement les préoccupations de vos clients, la transaction sera difficile à obtenir. audemars piguet montre La raison pour laquelle les clients sont vigilants et inquiets au sujet des vendeurs peut être qu’ils ont été victimes de tromperies lors de leurs expériences précédentes ou qu’ils ont acheté des produits pour se décevoir eux-mêmes.

JustinJune 7, 2019, 3:44 p.m.

Thank you for sharing these detailed about Combining Storyboards and XIBs in Xcode. .I truly like your post and amazing blog. I was extremely satisfied to discover this site. I needed to thank you for this extraordinary read!! Homestyle Loan

Deep sea atlanticnaJune 14, 2019, 5:25 p.m.

Eat the delicious Kingfish today at one of our hotels. We offer many more wild-caught seafoods from the deep sea. Visit our site for more information.

WalsmithJuly 25, 2019, 9:59 a.m.

Whether it's recommended Assignment writing services uk, I'm just curious if there are folks who try this. I'm interested in both writing and drawing, so I'd love to be able to do both. If there are people who've effectively drawn storyboards for their lively film screenplays, could you deliver me an example?

AmandaJuly 26, 2019, 6:38 a.m.

Merge Conflicts in Version Control. It’s always a painful experience when multiple developers are working on a project as it almost always leads to merge conflicts in storyboards. I have not heard this Can Someone Do My Essay For Me from many developers, but faced this issue in one of my projects. Using a huge storyboard leads to very slow loading for the application. Splitting it into multiple storyboards solved the issue for me.

liamAug. 6, 2019, 6:36 a.m.

I cannot even think what I would have done if there was no It has helped me so much as now I am able to merge all of the pdf files on the internet.

kevinAug. 8, 2019, 9:26 p.m.

ISP Bharat Sanchar Nigam Limited (BSNL) is the pioneer telecom in India, and the policies were further modified to introduce ISPs in the market, Several companies (Bharti Airtel, Reliance Jio Aircel, ACT, Vodafone, Idea Cellular) joined the Indian market, and BSNL Teleservices provides the best information on all telecom and infra services provided by BSNL, and the telephone density in the sector has increased more day by day.

bodyboss reviews and resultAug. 12, 2019, 3:32 p.m.

Bodyboss Reviews and Here is my before and After Results. BodyBoss Reviews: Everything you know must know before buying-Taking care of your body is a responsibility which is indispensible. ... You need good sleep, lots of water, a healthy diet and a fitness program that you can follow bodyboss reviews and result

dbsAug. 16, 2019, 9:49 a.m.


jamesAug. 25, 2019, 5:07 p.m.

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. gai goi

kevinSept. 1, 2019, 6:26 p.m.

Thanks so much with this fantastic new web site. I’m very fired up to show it to anyone. It makes me so satisfied your vast understanding and wisdom have a new channel for trying into the world.

mtomSept. 3, 2019, 3:30 p.m.

I am glad to read this post, it’s an impressive piece. I am always searching for quality posts and articles and this is what I found here, I hope you will be adding more in future. Best barber shop Birmingham

kevinSept. 4, 2019, 3:41 p.m.

I ‘d mention that most of us visitors are really endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.

Sumitsingh72Sept. 5, 2019, 10:19 a.m.

Shiftinindia packers and movers in Delhi is the solid and expert movers and packers local time in pune , packers and movers in company , moving cost estimator calculator , packers and movers in Pune charges

susan mayerSept. 9, 2019, 2:58 a.m.

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. things to do

donSept. 12, 2019, 7:41 a.m.

Kindly enhance all ios developers the design of the page and make the page the best. The best compilation of all these topics helps readers a lot. The best topics really help users to get more ideas through this page very easily.

forexsteam.comSept. 13, 2019, 1:48 p.m.

Forex Steam is a 100% automated trading solution. With over 25 years of experience in the Forex market our team has put together a system that provides long term growth in a low risk environment.

mtomSept. 14, 2019, 12:52 p.m.

you have a very excellent weblog here! if you’d like to make some invite posts in my small weblog? 사다리사이트

This is a great blog” and i want to visit this every day of the week .   Hair salon for men

selfieSept. 18, 2019, 11:26 a.m.

Welcome to the world of gaming, where life is fast paced and interesting. There is always an adventure waiting for you online.
cheap csgo accounts


Post New Comment