12

Currently we use Storyboard over xib in all projects. But in my view if you want to make reusable view (custom view or Tableview cell) which can be re-used in different view controllers, you must use xib files as in storyboard there is no way we can make single view object separately.

Note that I am using Storyboard for workflow (view controllers with segues all around) of entire application. Only for reusable tableview cells I am using XIB.

I have searched in lot of apple documents as well as WWDC videos but I could not find any concrete proof from Apple developers which says that XIBs are here to stay or you should use XIB for custom views.

If any of you guys have any kind of links which gives somewhat confidence that we can still use XIB without fear of apple removing it, it would really be appreciated.

Pradip Vaghasiya
  • 326
  • 3
  • 14
  • 1
    You can use more than one storyboard and reuse elements from within the storyboard in different parts of you App. And you won't win the arguments because Apple usually does not give detailed information about their future plans. Ask your seniors why they even use storyboards. Code will stay much longer than some strange format. – dasdom Jul 03 '14 at 11:33
  • Thanks for reply. As per my knowledge we can only create view controller as root object in Storyboard. isnt it? What if I want to just create small custom view. we must use xib(if not in code) right? – Pradip Vaghasiya Jul 03 '14 at 12:08
  • 1
    Yes, you are right. You can only get view controllers from storyboards ([instantiateViewControllerWithIdentifier](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIStoryboard_Class/Reference/Reference.html#//apple_ref/occ/instm/UIStoryboard/instantiateViewControllerWithIdentifier:)). Sorry about the confusion. – dasdom Jul 03 '14 at 12:18

3 Answers3

7

Storyboards are recommended when you don't reuse views.

Once you want to reuse something in multiple views/storyboards, then you need XIBs. You already mentioned the example of custom cells. That is something I need quite often and I want to use the same cell in multiple table views. I do the same with charts. I create a chart view in which I set colors etc. and I reuse it everywhere, only putting different data in it. This saves me a lot of code in respect to style/appearance and makes the app easily maintainable. In case of change (e.g. because of new iOS version), I need to change everything on a single place.

Furthermore, I want to have views (e.g. cells) for iPhone and iPad and let the system determine which one to use. For this, again, I need XIBs. I use the notation with ~iphone or ~ipad at the end and I don't have to write code for retrieving the correct view.

This are two things that you simply cannot do without XIBs. So, following the Apple guidelines, my approach is to use storyboards whenever possible and XIBs only when I need them (mainly because of reusability). But there are real cases when one needs XIBs! Simply ignoring them is not a good practice for sure. Actually, in each project I have storyboards as well as XIBs.

Edit: I just found a great post explaining the disadvantages of storyboards. There are plenty of things that I was not aware of.

Community
  • 1
  • 1
Antiohia
  • 1,142
  • 13
  • 37
2

Also, you don't have to use either exclusively. You can still use XIB files even if most of your work is in storyboard. And using either also doesn't restrict you from creating a view that isn't built in IB at all.

Storyboard has plenty, plenty of advantages. Particularly when you start bringing new people in on the project. Without getting engulfed looking at hundreds of thousands of lines of code, a new developer can look at the storyboard and in 30 minutes or less get a quite good idea of the flow of the app.

With that said, you should never limit yourself to anything. Limiting yourself to just storyboard and never using XIB or building a view completely in code is like saying "We're only going to use NSArrays, and never NSDictionary or NSSet". Instead of a silly limitation, you should always just be sure you're using the right tool for the job.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
0

My opinion is use which one is appropriate for that context, here is some guidelines:

When to use nibs

  • Modularity is key to well designed nib files
  • Use nibs to store views, subviews, custom controls or repeated views
  • There’s no way to represent the relationship between screens of related content

When to use Storyboards

  • Storyboards are best used to represent screens of content and the connections between those screens
  • Give due care and attention to the prepareForSegue:sender: method
  • Modularity is still applicable when designing storyboards

General Guidlines

  • Decompose your projects into nibs and storyboards
  • Views, subviews and custom controls should be contained within separate nib files Use storyboards when designing full screen content and there are clear relationships between scenes
  • Consider whether the interface needs to be static or dynamic
  • Use separate storyboards to encapsulate reusable sequences of scenes
  • Use separate storyboards for unrelated scenes
  • Table view cells that can be reused across different controllers belong in nib files
Yatheesha
  • 10,412
  • 5
  • 42
  • 45