Thursday, December 31, 2015

Convert Project from Storyboard to Xib

Objective C

Step 1)
//Add below code in  AppDelegate.h
@property (retain, nonatomic) UIWindow *window;
@property (nonatomic,retain) UINavigationController *navigationController;

Step 2)
Create New file ViewController subclass of UIViewController with Xib

Step 3)
//Add below code in  AppDelegate.m
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

ViewController *viewController=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;

Step 4)
Delete “Main storyboard file base name” line from info.plist file

Step 5)
Run Project

Swift

In didFinishLaunchingWithOptions Method in Appdelegate


        window = UIWindow(frame: UIScreen.mainScreen().bounds)
      
        let mainViewController = HomeViewController(nibName: "HomeViewController", bundle: nil)
      
        let navigationController = UINavigationController(rootViewController: mainViewController)
      
        window?.rootViewController = navigationController
        window?.makeKeyAndVisible()
      
        return true