Xib未按预期加载

时间:2015-01-04 12:27:20

标签: ios objective-c iphone xcode

我从头开始创建项目已经有一段时间了。当时在XCode 4/5中,开发人员可以在storyboard或Xib之间进行选择以启动项目。在Xcode 6中虽然每个模板都被强制启动为StoryBoard。

我删除了故事板。然后,我在支持文件中打开了info.plist,并将Main storyboard file base name : Main设置为Main storyboard file base name: <blank>

然后我用Xib(同名)创建了一个基本的testViewController。

@interface AppDelegate : UIResponder <UIApplicationDelegate>

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

@end



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    testViewController *firstViewController = [[testViewController alloc] initWithNibName:nil bundle:nil];
    self.navigationController.viewControllers = [NSArray arrayWithObject:firstViewController];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

这仍然显示我是一个黑色的视图控制器。我检查了xib文件,文件所有者设置为视图控制器,并且还设置了视图委托。 我错过了什么?

1 个答案:

答案 0 :(得分:0)

改变这两件事:

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

 testViewController *firstViewController = [[testViewController alloc] initWithNibName:nil bundle:nil];

为此,并使用真实姓名或您的xib文件添加此代码:

@property (nonatomic, retain) UIWindow *window;  // Are you using ARC?

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// I think your xib files is testViewcontroller.xib, if not change it.
testViewController *firstViewController = [[testViewController alloc] initWithNibName:testViewController.xib bundle:nil];
// change this also
self.navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];

self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;