2011-01-17 7 views
0

こんにちは、 私は以下の問題があります: 私はIPadアプリケーションを持っています。 (私はそれが他の方法でなければならないことを知っているが、私はそれを変更することはできません)。アプリケーションが実行されているデバイスに応じて異なるxibsからrootViewControllerを初期化する

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    // The device is an iPad running iOS 3.2 or later. 
} 
else { 
    // The device is an iPhone or iPod touch. 
} 

これはRootViewController exeptすべてのビューに適しています: は、だから今私が使って必要な表示かを決定します。
いいえ私は、RootViewControllerのxibを設定しますが、常にIPad-App用に定義したものを表示します。

これは、App-委任の私のコードです:

viewController = [VoycerUniversalAppViewController sharedInstance]; 


UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 
[self.window addSubview:myNavigationController.view]; 
//[self.window addSubview:self.vcSplashScreen.view]; 
[self.window addSubview:viewController.view]; 
[self.window makeKeyAndVisible]; 

return YES; 


は、そして、これは私の[VoycerUniversalAppViewController sharedInstance]内のコードです:私はほとんど見

+ (VoycerUniversalAppViewController*) sharedInstance 
{ 
    @synchronized(self) 
    { 
     if(sharedInstance == nil) 
     { 
      // only allocate here - assignment is done in the alloc method 
      if (![AppState sharedInstance].loggedIn) 
      { 
       [AppState sharedInstance ].loggedIn = FALSE;    
      } 
     } 
    } 
    return sharedInstance; 
} 

+ (id) allocWithZone:(NSZone*)zone { 
    @synchronized(self) { 
     if(sharedInstance == nil) { 
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
      { 
       // The device is an iPad running iOS 3.2 or later. 
       NSLog(@"The device is an iPad running iOS 3.2 or later."); 
       sharedInstance = [[super allocWithZone:zone] initWithNibName:@"VoycerUniversalAppViewController" bundle:nil]; 
      } 
      else { 
       // The device is an iPhone or iPod touch. 
       NSLog(@"The device is an iPhone or iPod touch."); 
       sharedInstance = [[super allocWithZone:zone] initWithNibName:@"VoycerUniversalAppIPhoneViewController" bundle:nil]; 
      } 
      // allocate and assign instance variable on first allocation      
      return sharedInstance; 
     } 
    } 
    return nil; 
} 


どこでも私はいくつかの設定や何かを逃したと思うが、私は何も見つけることができませんでした。
誰かがアイデアを持っていますが、なぜVoycerUnversalAppViewControllerを別のものの代わりに読み込むのですか?
両方のXibsは同じクラスにリンクされています。
ソリューションが非常にシンプルで分かりやすいのであれば、私を責めないでください。私はxcode、IB、およびobjective-c(私は1ヶ月半の目的で-cのコード)に本当に新しいです。

Thxです。
Maverick1st。

答えて

2

メインNIBの場合、info.plistファイルには、NSMainNibFileNSMainNibFile~ipadの設定があります。

NIBファイルでは、アプリケーションデリゲートを作成し、ナビゲーションコントローラを設定できます。

+0

プロジェクトを開始したとき、私の同僚がそうしてくれたので、私はDelegateと私のViewControllerを含むMainWindow.xibを作成しました。 MainWindow.xibで適切なView Controllerのxibファイルを変更しても、ビューには影響しません。それでも間違ったものが表示されます。私はIPadとIPhoneの両方に対してMainWindow.xibを1つしか持っていないので、NSMainNibFilesを両方ともinfo.plistのMainWindowに設定します。または、私はiPhone用の完全な新しいMainWindow.xibを作るべきですか? しかし、彼らが今働いていない場合でも、ヒントのためのthx。それは私の役に立つ情報でした。 :) – Maverick1st

+0

はい、2つのNIBを作成し、info.plistに追加します。それは動作するはずです。 –

+0

それはあなたのために働いたのですか? –

関連する問題