2011-04-11 35 views
1

我做了一個簡單的基於導航的應用程序。 它在iphone上運行得很好,但它不適用於ipad 3.2模擬器和設備。爲ipad 3.2設置rootViewController不起作用

in applicationdidfinish event;

MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil]; 
[self.navigationController pushViewController:viewController animated:NO]; 
self.window.rootViewController = self.navigationController; 
[viewController release]; 

它說,這條線:

self.window.rootViewController = self.navigationController; 

[一個UIWindow setRootViewController:]:無法識別的選擇發送到實例0x4c22dd0

,但它適用於iPad的4.2及以上。

我該如何解決它的iPad 3.2?

回答

5

UIWindow在iOS < 4.0中沒有rootViewController屬性。因此,您需要檢查版本(谷歌它),然後要麼設置RootViewController的,或添加navigationController的view作爲一個子視圖爲下面的窗口中,根據您的用戶運行的是什麼版本:

[self.window addSubview:self.navigationController.view]; 

快速編輯:檢查您是否可以使用rootViewController屬性,您可以檢查[self.window respondsToSelector:@selector(setRootViewController)]是否返回TRUE或FALSE。

+0

偉大的,它適用於所有iOS版本。我想我不需要檢查版本。因爲我不在IB中設置視圖控制器。謝謝... – fulberto100 2011-04-11 20:31:49

1

正確的方法是(不要忘記 「:」!):

if ([self.window respondsToSelector:@selector(setRootViewController:)]) 
    self.window.rootViewController = self.tabBarController; 
else 
    [self.window addSubview: self.tabBarController.view]; 
相關問題