11

I'm trying to create a project in Objective-C language without storyboard with Xcode 6 Beta 5. I have tried and created a empty project but it didn't work as Xcode 5.

I have read this topic How to create project without story board in Xcode 6 - Swift but it didn't help me.

1
  • It's my impression Apple is ushering devs using Interface Builder to move to Storyboards from XIBs (especially by removing the option and instead building them in by default). I can't find any concrete evidence but creating new projects in Xcode 6 only seems to yield Storyboard-based projects. Commented Aug 15, 2014 at 12:42

5 Answers 5

9

What do you mean it didn't work as Xcode 5? You can create empty project without storyboard and then add your own class with XIB like in Xcode 5: File -> New -> File -> Cocoa Touch Class -> Set "Subclass of:" as (for example) UIViewController and check "Also create XIB file".

Sign up to request clarification or add additional context in comments.

5 Comments

What I mean is that normally when you create a project in Xcode 5 you get an app delegate while I couldn't get it in the Xcode 6 in the empty project. I have did the same as you have written but I couldn't run the project.
You should get an app delegate. Can you provide screenshot of your project? What's in your main function? Are you sure you are creating "Empty Application" project from "Application" Tab and not just "Empty" project from "Other" tab? Looks like it's what you did. BTW it's the same in Xcode 5
I can't provide a picture because my reputation is under 20. First I click on create a new Xcode project > iOS (from left) > Empty icon (from right) > product name "". There is not Empty Application in "Application" Tab, while there is in Xcode 5. You can check that...
Checked that and I have this template. But I found out that Apple removes this template in beta 3 and I'm still using beta 2. So it appears that Apple forces you to use storyboards. Then you have 2 options, I guess: 1. Create project with storyboard and then delete storyboard and related code. 2. Copy "Empty application" template from previous beta to templates folder: {Xcode.app}/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application/
Thanks Alexander for your response I think from now I'll be using Storyboard :(
8

You first make a new "Single View" project. This starts out with a Storyboard, but as Xcode 6 has removed the option for creating an Empty project, we will just work with it from here.

You then create a new file for this project, go into the "User Interface" category and select "View". I would name it the same name as your original ViewController as it will replace the storyboard we are about to delete from the project.

Once the XIB is created, you will want to select it and set the "File's Owner" to point to the "ViewController" class that you want this XIB to link with. That is done by going into the Identity Inspector of the File's Owner of the Xib, and changing the default of NSObject to the class name of your view controller.

Once done with that, you want to go to the Connections Inspector to link the view of the File's Owner to the view of the XIB. Just click the little circle across from "view" and drag it over to your view to connect it. You should then have a connection between view and View.

Now the important parts. Go into your project Target, under the "General" tab. There is a subsection called "Deployment Info". In that subsection there is a field for "Main Interface". This field should be showing the name of the storyboard. You need to delete the value shown in this field, so that the Main Interface is left blank.

Then go into the App Delegate and set the root view controller of your window like you have been for previous versions of Xcode. Once that is done you should have a running app using your XIB, and you can delete your storyboard from the project without any adverse affects.

1 Comment

Thanks man, you saved my life. To set the root view controller, add this: self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // create an instance of the view controller you want to be displayed first UIViewController *homeViewController = [[UIViewController alloc] initWithNibName:@"CreatedViewController" bundle:nil]; // set it as the root view controller of the application's window [self.window setRootViewController:homeViewController]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible];
2

I don't know why people are down voting this as it is a legitimate question, so here is what you need to do:

Create an empty project, create a new view controller (File/New/File) - with XIB file if you need one, import the new view controller into your AppDelegate, and set this view controller as the root view controller.

AppDelegate.m:

#import "AppDelegate.h" // import the view controller you want to be displayed first #import "FirstViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // create an instance of the view controller you want to be displayed first FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; // set it as the root view controller of the application's window [self.window setRootViewController:firstViewController]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } 

Now, of course, if you wanted the create a tab bar or navigation controller, you would do this a bit differently, however this should be a good starting point for you.

2 Comments

Thanks Nick I followed you way but in Xcode 6 I don't get AppDelegate as you create an empty project in Xcode 5.
Every application will have an AppDelegate, no matter which template type you choose when creating it. If when creating your project you add a Class Prefix then it will be named XXAppDelegate. I am guessing this is different with Xcode 6 which I haven't used aggressively yet.
2

AppDelegate.h

UINavigationController *nav; 

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; ViewController *ll=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil]; nav=[[UINavigationController alloc]initWithRootViewController:ll]; [self.window setRootViewController:nav]; [nav setNavigationBarHidden:YES]; return YES; } 

Comments

0

It is very simple:

  • create empty application project
  • add to this project New File -> Objective-C class (with .xib file). My class is named "ViewController" :) Now you must create UINavigationController in AppDelegate.h e.g.:

    @property (strong, nonatomic) UINavigationController *navController;

than you must set your navcontroller in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. [self.window makeKeyAndVisible]; ViewController* homeViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; _navController = [[UINavigationController alloc] initWithRootViewController:homeViewController]; self.navController.navigationBarHidden = YES; self.window.rootViewController = self.navController; return YES; } 

Thats all.

2 Comments

Thanks I have did the same thing add to this project New File -> Objective-C class (with .xib file). My class is named "ViewController" but I couldn't run the project. I get my RUN button is empty not set on iPhone.
But when I create a normal project with storyboard I get the RUN button and it works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.