What is the difference between a .xib file and a .storyboard?
Asked Answered
F

6

168

Can someone explain in simple words the difference between .xib and .storyboard?

Flamenco answered 8/12, 2011 at 19:13 Comment(4)
I have no idea what a .timeline is, and I suspect it has nothing to do with the Facebook timeline that the tag refers toOlympium
are these two completely separate questions, George? Also, when you say .timeline, are you talking about versions of a saved file?Geostatic
You had two separate questions here, so I refined it to just one. The first question has been asked a few times around here, such as in Cannot find window-based application on XCode , so I removed that part to focus on the Storyboarding question.Randyranee
See also this similar question, When to use Storyboard and when to use XIBs. Has excellent detailed answers including updates for iOS 8 and Xcode 6.Prevocalic
S
120

Apple introduced the concept of "storyboarding" in iOS5 SDK to simplify and better manage screens in your app. You can still use the .xib way of development.

Pre-storyboard, each UIViewController had an associated .xib with it. Storyboard achieves two things:

  1. .storyboard is essentially one single file for all your screens in the app and it shows the flow of the screens. You can add segues/transitions between screens, this way. So, this minimizes the boilerplate code required to manage multiple screens.

  2. Minimizes the overall number of files in an app.

You can avoid using Storyboard while creating a new project by leaving the "Use Storyboard" option unchecked.

You could refer this tutorial to get started.

Sequoia answered 8/12, 2011 at 19:33 Comment(5)
So does storyboarding replace the need for .xib files?Constrain
Ideally, Yes. 1 .storyboard file = 'n' no. of .xib files.Sequoia
What about for transitions between views, though? I know that there are segues, but there are only a few different styles of segues. I assume that you can still transition between views the same way as before, but if you are not using a segue, it would look weird in the storyboard, right? What are your thoughts on that?Disclosure
In that case, I believe the NavigationControllers would come into play?Sequoia
fun fact: I use this post to show-off my (limited) iOS cred :DSequoia
O
23

Yes, you can still create a Window-based application for iOS 5. If you use the "empty project" template, you will see that a window is created for you in the app delegate. From there you can add XIB files as normal, or a new storyboard.

I'm assuming you mean "storyboards" rather than "timeline". Storyboards allow you to map out, visually, all of the views in your applications and how they interrelate. If you are just starting out with storyboards, there's an introduction to storyboards in the WWDC 2011 videos here. The 2011 Stanford iOS course on iTunes-U is also iOS 5-specific and covers storyboards and more.

Overijssel answered 8/12, 2011 at 19:18 Comment(0)
N
16

A storyboard is like a canvas where you put all your .xib files. You no longer have any .xibs, you just have View Controllers directly on your canvas.

Newhall answered 3/11, 2012 at 22:36 Comment(1)
Possibly the most useful answer.Caudal
T
9

storyboard is a new feature available since the release of Xcode 4.2. It offers a complete new way for iOS developer to create and design user interface. Before the introduction of Storyboard, it’s especially hard for beginner to create navigation (and tab) interface. Every interface is stored in a separate xib file. On top of it, you have to write code to link all interfaces together and describe how the navigation works.

With Storyboards, all screens are stored in a single file. This gives you a conceptual overview of the visual representation for the app and shows you how the screens are connected. Xcode provides a built-in editor to layout the Storyboards. You can define the transition (known as segues) between various screens simply using point and click. This doesn’t mean you do not need to write code for the user interface. But Storyboards significantly reduce the amount of code you need to write.

Source: http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/

Talon answered 11/10, 2014 at 12:22 Comment(0)
M
2

XIB:

  1. Xib files are used with a single UIView.

2)It's very difficult to implement complex auto-layouts in xib.

3)It's utilizes more memory as compared to storyboard and quiet slow.

  1. It is compatible from iOS5 and onwards

  2. You can do localizations for different languages and countries using different XIBs .

  3. It's difficult to use same Xib to support multiple devices.

Storyboard

1)You can layout all your Scenes like View Controllers, Nav Controllers, TabBar Controllers, etc in a single storyboard.

2)You can use Auto Layout easily that defines mathematical relationships between elements defining their position and sizing.

3)Usually fast and allocates less memory.

4)It's not compatible prior to iOS 5 .

5)"Dynamic" and "Prototype" cells can be used easily.

6)Storyboards best to use for the apps with a small to medium amount of screens.

The best Answer I have seen : Xib Vs Storyboard in iOS

Matrimonial answered 30/11, 2017 at 19:17 Comment(0)
G
0

XIB and Storyboard are used for creating interfaces for users.

One important point is,xibs are used for creating a single view(it has single file owner at the top of the xib file), but in-case for viewcontroller, multiple screens can be added and its flow can also be monitored(it has separate file owners).

Gwenora answered 1/3, 2018 at 5:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.