List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Saturday, November 15, 2014

Xcode 6 Creating Xib From StoryBoard

The first step is to remove Main.storyboard, LaunchScreen.xib, ViewController.h, and ViewController.m—select them all, right-click, and choose to either remove them from the project, or delete them completely:
If you run the app at this point, you’ll get an exception: “Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Could not find a storyboard named ‘Main’ in bundle…” This is because the project is trying to use that storyboard file you just removed. This information is in the project’s Info.plist, and the entry is “Main storyboard file base name”:To fix this, simply remove the entry (select it and hit delete or hover and click the remove icon).
Open AppDelegate.m, and edit applicationDidFinishLaunchingWithOptions so that it looks like this:
 
- (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.window makeKeyAndVisible];
    return YES;
}

In order to get to the functional equivalent of an Xcode 4 Single View Application, we need to add a View Controller and its corresponding xib file, and hook them up. The first step is to add a subclass of UIViewController and a corresponding xib file. Use ⌘-N or the File->New->File.. menu item to create a new file, and select “Cocoa Touch Class”: The next dialog asks you to name the class; I cleverly called mine “ViewController”. Make it a subclass of “UIViewController”, and check the “Also create XIB File”:
This will create three files in your project: ViewController.h, ViewController.m, and ViewController.xib:

Running the app at this point will give you the same behavior as before, as we’ve not yet told your app to actually use the ViewController. To do this, we need to add a property to the AppDelegate, to hold the ViewController; edit AppDelegate.h so it looks like this:
#import
 
@class ViewController;
 
@interface AppDelegate : UIResponder <UIApplicationDelegate>
 
@property (strong, nonatomic) UIWindow *window;
 
@property (strong, nonatomic) ViewController *viewController;
 
@end
 
and then edit didFinishLaunchingWithOptions  so it looks like this:
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

No comments:

Post a Comment