简体   繁体   中英

How can i use xib files instead of storyboard in Xcode 5?

I'm very new to ios developing and many of the tutorials i watch follow the xib approach since they were recorded before XCode 5. How can i go with the xib approach in Single View Application? When i delete storyboard and select one of the xib's as the main interface it's not working. Thanks for any tip.

add new file in that select the cococatouch and select the Objective -C class and then go to the next click.
you show the below screen
at the bottom must select the with xib for user Interface.and next

AppDelegate.h:

@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    ViewController *viewObj;
    UINavigationController *navObj;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic)  ViewController *viewObj;
@property (strong, nonatomic) UINavigationController *navObj;

AppDelegate.m:

@synthesize viewObj,window,navObj;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    viewObj = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    navObj = [[UINavigationController alloc] initWithRootViewController:viewObj];

    window.rootViewController=navObj;
    [window makeKeyAndVisible];

    return YES;
}

在此输入图像描述

Select Empty application template while creating new project.
Select Cocoa touch from left pane -> objective-c class -> then give name of viewController and tick option of Xib user interface.

and then in apply below code in appDelegate file:

appDelegate.h File:

#import <UIKit/UIKit.h>
#import "HomeViewController.h"

@interface HomeAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong,nonatomic)HomeViewController *homeViewController;
@property (strong,nonatomic)UINavigationController *navigationController;

appDelegate.m File:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    self.homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc]initWithRootViewController:self.homeViewController];
    self.window.rootViewController = self.navigationController;


    [self.window makeKeyAndVisible];
    return YES;
}

  @end

you can do it by following these steps:-

  • Create a new project
  • Select Single View Application
  • Set ProjectName and other settings
  • Save Project at location
  • Select Project in Navigator Panel in Left
  • Remove Main.storyboard file from project
  • Add New .xib file in Project
  • Set Main Interface to your .xib file in "General Tab" on right panel.
  • Paste following code in didFinishLaunchingWithOptions method

     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.viewController = [[ViewController alloc] initWithNibName:@"YourViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; 

Courtesy:- MKR

https://stackoverflow.com/a/19633059/1865424

Just check it have you missed any of the step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM