How to use xib files instead of storyboards in Xcode 5?

I am very new to ios development, and many of the tutorials that I watch follow the xib approach as they were written before Xcode 5. How can I go with the xib approach in Single View? When I delete the storyboard and select one of xib as the main interface, it does not work. Thanks for any advice.

+6
source share
3 answers

add a new file in which select cococatouch and select Objective -C class, and then go to the next click.
you show below screen
below you need to choose with xib for the 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; } 

enter image description here

+11
source

Select Blank application template when creating a new project.
Select Cocoa, tap the left pane -> objective-c class -> then specify the name of the viewController and check the Xib UI option.

and then in apply below code in appDelegate file:

File appDelegate.h:

 #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 
+7
source

You can do this by following these steps: -

  • Create a new project
  • Choose a single view application
  • Set project_name and other parameters
  • Save project in place
  • Select a project in the left navigation bar.
  • Delete the Main.storyboard file from the project
  • Add a new .xib file to Project
  • Install the main interface in your .xib file in the "General tab" in the right panel.
  • Paste the following code in the 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]; 

Provided by: - ​​MKR

fooobar.com/questions/446882 / ...

Just check if you have missed any step.

+1
source

All Articles