11

I've been tasked with creating an app, but I have zero experience with iOS development. I have general programming knowledge, particularly with Java, JavaScript and PHP (I'm more a web developer than a programmer). I have dabbled with C, Xcode and various other languages and IDEs in the past, but I remember very little.

I've been following Apple's Developer Library tutorials, and I'm at around the Language stage, where I'm come to a grinding halt. While I slowly progress through learning the basics of Objective-C, there are a few things I'm very confused about regarding development in Xcode that various tutorials seem to completely skip over or just imply that you know what to do, or some just stop right before the part I'm having trouble with.

1) Storyboard - yes or no?

Is it better to start with an empty application and work with the files or create a template (in my case a tabbed application) and work with the storyboard?

2) If using a storyboard, do I still need to have a .xib?

Are the User Interfaces more like global templates that the view controllers implement?

If I wanted a different layout for each tab of my app, would I create a .xib for each tab, or just edit the controllers in the storyboard? Am I correct in understanding that the storyboard can have multiple instances/relationships of the same controller, in which case having .xib's would make more sense?

3) If using storyboard, where do the implementation and source files come from?

This is probably a stupid question. I know you can just add them via File -> New, but I don't know how to associate those files with a view controller. Is there a way to have the files created automatically when adding a controller into the storyboard?

user1548843
  • 670
  • 12
  • 20
  • 4
    +1 for **having done research of your own.** As to the question: storyboards - use them if you like them. Some love them, some hate them. 2. SB vs XIB: AFAIK they are mutually exclusive (nevertheless, they can be used for implementing different parts of the same project). 3. SB and implementation: Interface Builder is **magic** - it is hardcore black woodoo. I don't use it and as such, I don't know a lot about it, but AFAIK it's IB that makes these connections automatically. –  Sep 04 '13 at 06:00
  • 1
    @H2CO3 Yes but he used the word "Xcode" in the title and tags... you are getting soft. But +1 anyway for the same reason. – trojanfoe Sep 04 '13 at 06:02
  • 1
    @trojanfoe :D Well, I feel this *has* something to do with Xcode - apparently, he's asking about Interface Builder which wouldn't be applicable if he used `emacs`. –  Sep 04 '13 at 06:04
  • 1
    @H2CO3 Hmmm, tenuous, but you might be right. In fact you are right as he specifically mentions menu options in Xcode. The prosecution withdraws its statement... – trojanfoe Sep 04 '13 at 06:04
  • @trojanfoe Apparently, our defendant is an experienced programmer, and that's an extenuating circumstance. He won't hopefully litter Stack Overflow with "what does undefined symbols mean"-style questions, despite the fact that he does **not** use `emacs` ;-) –  Sep 04 '13 at 06:09
  • @H2CO3 Not using emacs is a well established lifestyle choice on modern Earth, however I concur. – trojanfoe Sep 04 '13 at 06:13
  • 1
    @H2CO3 After six years of computer science at university, I never wanted to hear the word "emacs" being uttered again. – Robert Gillman Sep 04 '13 at 06:21
  • @RobertGillman :)) Substitute your favorite command-line text editor. `vi`, `nano`, whatever you like -- it's just that `emacs` is quite generally recognized and as such, it can be used as a symbol of IDE-less (?) development. If you wish so: I don't use it either, my fave command-line editor is `nano`. –  Sep 04 '13 at 06:28
  • @H2CO3 I'm not one of those "hardcore" programmers that does everything by command line. Granted I can create a whole website with just Notepad, but when it comes to app development, even if I were experienced, I'd need an IDE. – Robert Gillman Sep 04 '13 at 06:34
  • 1
    @RobertGillman Yeah and that's fine. I was primarily talking about people (especially beginners) who have no idea about how the underlying stuff works. They start out with a nice IDE, then they can't resolve a simple linker error and post the 82846624929th duplicate question on Stack Overflow. That's what is bad, not using an IDE itself (that would be brainless to assert). –  Sep 04 '13 at 06:43
  • @RobertGillman 1) use storyboards, they're nice :) if you have a large number of screens, you can always have more than one storyboard. 2) you can have both if you wish, I use XIBs for custom views as storyboards do not allow for this (only XIBs allow you to have a UIView as the base unit/building block) 3) You create the implementation files. when you drag a uiview controller onto the storyboard, click on Utilities > Identity Inspector and set the UIViewController's class to be one you have already created. – bennythemink Sep 04 '13 at 07:10
  • @bennythemink Do I have to have separate .h/.m files for each view controller, or could I hypothetically have a single pair of files that handles all controllers? Also, could I have a single header file and an implementation file for each view controller, each of which import the same single header file? I'm a bit confused about how a tabbed application should ideally be built in terms of controllers in particular regard to the .h and .m files. – Robert Gillman Sep 04 '13 at 08:06
  • @RobertGillman yes, have separate .h/.m files for each view controller. Separation of concerns :) If all your view controllers need to import the same .h file then you could just include it in the .pch file in the Support Files group, but be aware this imports it into all files. – bennythemink Sep 04 '13 at 23:36
  • Robert, did you come to a solution? If so, mark an answer please – hybridcattt Oct 15 '13 at 12:09

3 Answers3

2

Since you're just starting, you should use Storyboards because it lets you link different view controllers(pages on your app, essentially) visually and outside of code. For example, you can link your UITabbedViewController (the part that manages the content of the other tabs) to the pages that represent the content of the different tabs. Basically, your storyboard would have the tabbed view controller in a parent-child relationship with the sub-controllers. You would have one instance of each -- the tabbed view controller, managing an instance of each of the tabs' content and controller. This is the same regardless of Storyboard or xib, but you can connect this more easily in the storyboard.

You can still use a .xib(nib) file for stuff like Custom Table cells or in cases where you want to separate a view element or controller from a storyboard where there are other constraints.

In the storyboard, you subclass the controller class on the sidebar in the visual editor by entering your subclass of say UITabbedViewController in 'Custom Class'. In your file associated with 'MyTabbedController', you implement your stuff.

Great book:

http://www.barnesandnoble.com/w/beginning-ios-6-development-david-mark/1113216077?ean=9781430245124

Good luck!

Nick C
  • 514
  • 3
  • 12
2

Storyboards can be appropriate for small applications, where you have ten or twenty screens. When your app contains more than that, you will just get lost in storyboard schema, where all your view controllers will visually look the same.

I prefer not to use storyboard, just separate xib files for each controller.

If you use storyboard, you can create xib files for other parts of application that is not related to SB, and view controllers that is involved in SB has their interface stored in SB, meaning you will have to design them in there, in this one huge storyboard file. I find this very uncomfortable.

As you are new to IB, I would like recommend you to take a look at Auto layout. There is no magic anymore :)

hybridcattt
  • 3,001
  • 20
  • 37
  • 1
    If I start out using a storyboard, would it be easy to convert to just using xibs later on if necessary? Is the storyboard is just a visual representation of the actual controller files, or does it encapsulate all the view object information? – Robert Gillman Sep 04 '13 at 08:09
  • Storyboard encapsulates all view information, it does not use any external files, only one .storyboard file. It was created this way intentionally to reduce number of files in projects. About that good answer is here http://stackoverflow.com/questions/8436324/what-is-the-difference-between-a-xib-file-and-a-storyboard As far as I know there is no way to migrate from SB to xibs. – hybridcattt Sep 04 '13 at 11:30
2

To answer on a point-by-point basis:

  1. I typically use the "Single View" template. It provides everything you need for your first view and can take it from there. It's a clean slate but it already has that first view which will be exactly the same code in 99% of the applications you make.

  2. No, the storyboard file is your xib. You used to have to make a new xib for each new layout, but then Apple introduced storyboards. A storyboard is basically all of your xib's in one file. Rather than make a new xib, drag a new ViewController object onto the document. You typically only have 1 storyboard file or 2 if you want to support both iPhone and iPad layouts.

  3. I don't think you can have it create your source files automatically, but its fairly easy to connect them manually.

Select the ViewController that you want to connect to your source files by clicking on that black bar beneath it. Then go to the bar on the side and go to this panel:

enter image description hereThere you enter the name of your custom ViewController subclass where I have put "MyViewController". Hope that helps!

WolfLink
  • 3,308
  • 2
  • 26
  • 44