Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load view form StoryBoard that does not have a Segue

I am really liking having all of my view's laid out in the Storyboard but there are times when I will have a view that is shown based on a button that is generated by code so there will be no Segue reference - it will be totally disconnected in the Storyboard. I would still like to design it in the storyboard though so I can have a nice overview of all my screens.

Is it possible for me to load the XIB (or whatever it is in a storyboard) designed in the storyboard when a UIViewControler is loaded?

like image 463
Slee Avatar asked May 19 '12 14:05

Slee


People also ask

How do you add embed segue to a storyboard?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.

How do you set a segue identifier in a storyboard?

Open Main. storyboard and select the segue named Show segue to “Choose Game”. Then from the Attributes inspector change its Identifier to PickGame.

How do you load a nib on a storyboard?

If you want to load the view from a nib in code you would just instantiate it directly using the same technique. All the subclass does is take the code to instantiate the view from a nib and put it in a hook for the storyboard to use.

How do I segue to another view controller?

Well, in addition to that, Ctrl+dragging also helps set up segues. So, Ctrl+Drag from the “Go to Other View Controller” button, to somewhere in the second View Controller. It can be anywhere in the main box of the second view controller. When you release, it will show you a box like the one below.


1 Answers

I do this in my projects:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *myController = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
[self.navigationController pushViewController: myController animated:YES];

Just make sure you have set your controller's identifier correctly. You can do this by:

  1. selecting the controller in Storyboard
  2. in the Utilities panel, click the Attributes inspector. Whatever you decide to put in the Identifier field is what goes in the 'instantiateViewControllerWithIdentifier' statement.

I hope this helps.

like image 112
titusmagnus Avatar answered Nov 16 '22 01:11

titusmagnus