Reputation: 1401
I created empty IOS project and want to create UI. I searched for information about connecting storyboard to code but there is nothing about it, just about xib files. So is it possible to use storyboard instead xib in empty project? And how?
Upvotes: 3
Views: 6517
Reputation: 1108
First create an empty project with some class name
then create an storyboard from file->userInterface->storyboard
then give a name for the storyboard after that press storyboard in the left menu and place a viewcontroller and hold viewcontroller give class name as already created Uiviewcontrollerclass
finally press project choose main interface as ViewController.storyboard
if you wanna code suppose segue use [self performSegueWithIdentifier: @"nameofcontroller" sender: self];
if don want segue go like this
[self performSegueWithIdentifier: @"TheSequeName" sender: self]; The @"TheSequeName" is defined when you ctrl drag a button to open a new view controller on the storyboard
If you don't use segue, there are many variants to open a new view controller. The basic one is using a separate NIB (without storyboard)
SecondViewController *view = [[SecondViewController allow] initWithNibName:@"NibName" bundle:nil];
If you declare your view controller on Storyboard, you can use
viewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"viewStoryboardId"];
Then you show your viewController using navigation controller
[self.navigationController pushViewController:view animated:YES];
Hope it works
Upvotes: 2
Reputation: 16543
You can get the storyboard object like this assuming you have a Storyboard file already in the Project
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
YourViewController *yourVC = [storyBoard instantiateViewControllerWithIdentifier:@"identifier"];
//Do whatever with the viewcontroller object
[self.navigationController pushViewController:yourVC animated:YES ];
Note:
Upvotes: 5
Reputation: 952
New File - > Objective-C Class (of type View Controller) -> without Xib file
now on on storyboard, go to that particular xib file
in property window -> Show Identity Inspector -> change class to above added ViewController.
That's it, now you can control your storyboard xib files from code.
Upvotes: 0
Reputation: 1472
From the 'File' menu, create a new Storyboard
.
Call it Main.storyboard
.
In your project settings, set it as the main interface file under the Deployment Info.
Upvotes: 0