0

New to iOS, just wondering if someone could explain the point of the storyboard.

If i create a view controller and programmatically add to it, what do i need a storyboard for?

Is it only for custom views? custom tables? etc

Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
NorCalKnockOut
  • 870
  • 3
  • 10
  • 26
  • possible duplicate of [What are the benefits of using Storyboards instead of xib files in iOS programming?](http://stackoverflow.com/questions/9083759/what-are-the-benefits-of-using-storyboards-instead-of-xib-files-in-ios-programmi) – Krumelur Jul 18 '14 at 20:13
  • Instead of xib files... What if you dont use storyboards or xibs and just generically make the views. – NorCalKnockOut Jul 18 '14 at 20:14
  • Did you read the accepted answer? I think it answers your question (unless you are really asking what is the point of declarative UIs, for which I am sure there are a lot of questions already) – Krumelur Jul 18 '14 at 20:16
  • Creating the views from scratch make it extremely hard to debug graphical issues. Can you imagine having a complicated VC with multiple nested views that all have different frames? Good luck editing those pixels. The only reason to programmatically create views with the objects pixel-by-pixel is if you're on a large team and GIT/SVN conflicts are a concern. Storyboards/XIB really hate being opened and will often cause changes just by viewing it within xCode – LyricalPanda Jul 18 '14 at 20:17

2 Answers2

0

From Apple's Document:

Storyboards Storyboards are the recommended way to design your app’s user interface. Storyboards let you design your entire user interface in one place so that you can see all of your views and view controllers and understand how they work together. An important part of storyboards is the ability to define segues, which are transitions from one view controller to another. These transitions allow you to capture the flow of your user interface in addition to the content. You can define these transitions visually, in Xcode, or initiate them programmatically.

You can use a single storyboard file to store all of your app’s view controllers and views, or you can use multiple view storyboards to organize portions of your interface. At build time, Xcode takes the contents of the storyboard file and divides it into discrete pieces that can be loaded individually for better performance. Your app never needs to manipulate these pieces directly. The UIKit framework provides convenience classes for accessing the contents of a storyboard from your code.

For more information about using storyboards to design your interface, see Xcode Overview . For information about how to access storyboards from your code, see the UIStoryboard Class Reference .

ukim
  • 2,395
  • 15
  • 22
  • Do you have to have a storyboard view for a controller? Can you generically make a controller and push to that view with no storyboard or xib? – NorCalKnockOut Jul 18 '14 at 20:16
  • @user2891803 look at my comment above. – LyricalPanda Jul 18 '14 at 20:19
  • You don't have to. You create and present a view controller programmatically. You can even use code to create a view without view controller and add the view to the view hierarchy. @user2891803 – ukim Jul 18 '14 at 20:20
0

Long story short, my understanding of storyboard purpose is as follows:

  • Less code -> less bugs
  • Visual representation of UI layout simplifies UI creation (views hierarchy, autolayout constraints)
  • Extremely simple way to set objects' properties (e.g. delegates, gesture recognizers) just by control-drag
Nikolay Mamaev
  • 1,474
  • 1
  • 12
  • 21
  • Okay thanks. Is it "acceptable" without causing some errors to make view controllers without a storyboard element or xib? – NorCalKnockOut Jul 18 '14 at 20:21
  • @user2891803 You definitely can do it without a storyboard or xib. There are companies that completely do everything via code. But it'll take you much longer to get your views to look correct. Storyboard/XIB is really mainly to help you style your UI very quickly. Most of what you do in storyboard is literally setting view.center = X,Y. So you can do it without a storyboard/XIB. But no matter how many people you ask, the general rule of thumb is there is almost no downside to Storyboard/XIB. It is mainly there to make your UI in a fraction of the time and let you see the flow of your app. – LyricalPanda Jul 18 '14 at 20:27
  • @user2891803 - It's certainly done, and in a limited number of circumstances it makes sense. A bit more common is to have an XIB representation that is partially blank and fill it in programmatically. – Hot Licks Jul 18 '14 at 20:28
  • @user2891803 Sure you can create view controllers, views and any other objects programmatically if you like this way. Will this implementation contain errors or not - it's defined only by your skills level. Interface Builder lets you get rid of many errors you may make because of lack of attention or experience. This is just a matter of efforts you're spending on building UI. Once you've spend some time on storyboards learning, you'll be able to create quite complex UIs within minutes whereas creating them programmatically may require tens of minutes :) – Nikolay Mamaev Jul 18 '14 at 20:29
  • @user2891803 - And I would encourage users to try their hand at fully programmatic VCs once or twice, even if there is no "need". It will make the whole process far less mystical. – Hot Licks Jul 18 '14 at 20:30
  • @user2891803 And last but not least, other developers can get into your code much easier and fix any bugs with much less pain if layout is defined visually, not in code. – Nikolay Mamaev Jul 18 '14 at 20:32