2014-02-15 56 views
1

我修改了現有項目的應用程序委託默認爲一個標準的應用程序委託,並使其加入我的自定義視圖控制器的觀點到現場,一旦它推出:爲什麼我的UIView無法加載?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    SplashScreenController *controller = [[SplashScreenController alloc] init]; 
    [self.window addSubview:controller.view]; 
    return YES; 
} 

我不明白的是,爲什麼ISN」我的觀點顯示?屏幕始終是博黑裝車後,因爲我肯定可以看到視圖其實負荷做:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    NSLog(@"View did load."); 
} 

回答

0

我想通了。我沒有在視圖控制器中分配窗口,也沒有使窗口鍵和可見。該代碼應該是作爲委託如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    SplashScreenController *controller = [[SplashScreenController alloc] init]; 
    [self.window addSubview:controller.view]; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
+0

,你不要將viewcontrollers視圖添加到窗口中!你真的想使用[self.window setRootViewController:controller]方法 - 如果你再次使用UIKit,一切都會導致痛苦的世界! – LordT

+0

@LordT哦,是的,像wh在? – Alexandru

+1

推送視圖不一定能工作了,或者可能在下一個版本的操作系統中不再工作,rootViewController getter不起作用,模態地顯示視圖可能失敗,等等。 – LordT

2

我有一個很難理解你想要做什麼,但它看起來像你的意思是設置你的窗口的根視圖控制器。試試這個:

SplashScreenController *controller = [[SplashScreenController alloc] initWithNibName:@"theNibName" bundle:nil];    
[self.window setRootViewController:controller]; 
+0

我的意思是,我改變了默認的cocos2d的應用程序委託的邏輯正常的iOS應用程序的代理,並正嘗試加載一個簡單的視圖到屏幕上。不幸的是,在我的應用程序委託的窗口上設置根視圖控制器似乎仍然顯示一個黑色的窗口:( – Alexandru

+1

@Alexandru當然,它只是分配/初始化視圖控制器的一個空白實例如果你想利用什麼你已經在你的xib中創建了,你需要使用initWithNib:在我的文章中看到新的代碼 –

+0

即使在Nib名稱爲「SplashScreenController」或「SplashScreenController.xib」,它仍然顯示爲黑色 – Alexandru