将故事板设置为起始文件而不是xib

时间:2013-12-18 11:23:58

标签: ios iphone objective-c uiviewcontroller uistoryboard

您好我有一个基于xib的项目,然后我添加了一个故事板“main.storyboard”。但它仍然运行与初始屏幕替代故事板相同的xib。

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.

以下图片确保我已将故事板作为起始屏幕。

我的xib文件的旧app app委托,现在我从这里替换xib uiviewcontroller类并放入我的新storyboard viewcontroller类名

.h文件

#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文件

#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;
}

3 个答案:

答案 0 :(得分:8)

您应该打开Info.plist文件并删除“主nib文件基本名称”键(或键)。 还要确保“主故事板文件名基础”键包含没有扩展名的故事板的名称。

然后修复main.m文件中的代码。使用以下行替换UIApplicationMain来电:

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

答案 1 :(得分:0)

在您的申请didFinishLaunchingWithOptions下:在appdelegate中 插入此代码:

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

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

答案 2 :(得分:0)

你错过了一点。尝试:

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