2015-01-04 128 views
0

自從我從頭開始創建項目以來,這已經有一段時間了。當時在XCode 4/5中,開發人員可以在storyboard或Xib之間進行選擇以啓動項目。在Xcode 6中,儘管每個模板都被迫作爲StoryBoard開始使用。Xib無法正常加載

我已經刪除了故事板。然後我在支持文件中打開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文件,將文件所有者設置爲視圖控制器,並且還設置了視圖代理。 我錯過了什麼?

回答

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;