0

In a normal view controller's nib you can instantiate and configure objects and they don't have to be child views of the file's owner's (view controller's) view. I find it useful to create and configure buttons and labels "on the side" so I don't have to do it programmatically. I can connect my view controller's outlets to them and add them to a view when I want to.

This doesn't seem possible with storyboards. Should I just create a separate nib for stuff like that and load it via NSBundle? Am I missing something?

zekel
  • 9,227
  • 10
  • 65
  • 96

2 Answers2

1

You can instantiate an unconnected UIViewController (or other controller) from a storyboard with the code below. You have to set the identifier in the Identity inspector for that view. I don't think you can just have free floating buttons or UIViews on their own (at least I have never seen or done that) - has to be a controller of some kind. If you have subclassed the controller (as in the example below) you specify the class in the Identity inspector.

     modalViewController = (AlertDisplayViewController * )
    [[UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:NULL] 
     instantiateViewControllerWithIdentifier:@"alertDisplayView"];
spring
  • 18,009
  • 15
  • 80
  • 160
  • That's what I was afraid of. If there isn't a better solution, I'll probably just store it in a separate nib and load it via `NSBundle`. – zekel May 06 '12 at 21:28
1

Try dragging the object to the "Scene" in the Document Outline (left-hand pane in Storyboard editor) or to the area underneath the scene in the main view (where the little icons for the View Controller, First Responder, etc. are.) I think that's probably the Storyboard equivalent of what you're talking about.

The object then sits "alongside" the View Controller, not as a child, and can be configured in IB by clicking on its icon (or entry in the Document Outline) and editing its properties, connected to code using outlets by dragging from the icon, etc.

Document Outline Tray

Matt Gibson
  • 37,886
  • 9
  • 99
  • 128
  • 2
    But – in the case of dragging in a UIView or any of its subclasses (such as the UIButton in your screengrabs) – is there a way to see the view itself in the editor and edit it and any subviews of it in the normal WYSIWYG fashion? Or is one limited to editing only by the inspector settings? – Slipp D. Thompson Oct 08 '13 at 21:08