CAN
CAN

Reputation: 1717

How to create an iOS project with a XIB in Xcode 6?

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.

Upvotes: 11

Views: 17306

Answers (5)

Robert
Robert

Reputation: 3870

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.

Upvotes: 0

Nilesh Parmar
Nilesh Parmar

Reputation: 399

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;
}

Upvotes: 2

Will
Will

Reputation: 81

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.

Upvotes: 8

Nick
Nick

Reputation: 949

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.

Upvotes: 2

Alexander
Alexander

Reputation: 126

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".

Upvotes: 9

Related Questions