简体   繁体   中英

Set storyboard as starting file instead of xib

Hi i have a xib based project then i have added a storyboard "main.storyboard". But it still running the same xib as initial screen stead of storyboard.

2013-12-18 16:44:14.376 AePubReader[1882:60b] NSMainNibFile and UIMainStoryboardFile are both set. NSMainNibFile ignored.
2013-12-18 16:44:14.396 AePubReader[1882:60b] There is no app delegate set. An app delegate class must be specified to use a main storyboard file.

the following images are make sure that i have given storyboard as starting screen.

my old app delegate for xib file ,now i replace xib uiviewcontroller class from here and put my new storyboard viewcontroller class name

.h file

#import <UIKit/UIKit.h>


@class viewViewController;

@interface AePubReaderAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;

    viewViewController *detailViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet viewViewController *detailViewController;

@end

.m file

#import "AePubReaderAppDelegate.h"


#import "ViewController.h"


@implementation AePubReaderAppDelegate

@synthesize window, detailViewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

//    // Override point for customization after app launch.
//    
//   self.window.rootViewController = self.detailViewController;
// [self.window makeKeyAndVisible];
//    
//   // [detailViewController loadEpub:@"ker"];

    return YES;
}

You should open the Info.plist file and delete the "Main nib file base name" key (or keys). Also make sure that "Main storyboard file name base" key contains the name of your storyboard without extension.

Then fix code in you main.m file. Replace UIApplicationMain call with following line:

UIApplicationMain(argc, argv, nil, NSStringFromClass([AePubReaderAppDelegate class]));

Under your application didFinishLaunchingWithOptions : in the appdelegate insert this code:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Your Soryboard name"  bundle:nil];

// Instantiate the initial view controller object from the storyboard
initialViewController = [storyboard instantiateInitialViewController];

You missed a bit. Try:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"main.storyboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];

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