2012-03-02 11 views
0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease]; 
    } else { 
     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease]; 
    } 

    CustomView1 *CustomView = [[CustomView1 alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.viewController.view = CustomView; 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

これは私がCustomViewからrootViewcontrollerの表示を変更したい、と上記のコードを試してみましたが、背景色が黒とタッチイベントが受け入れられなかった残っAppDelegate.mrootViewControllerのビューを変更するには?

に表示されます。

どこがエラーですか?

答えて

1

フォールトはどこにあるのか分かりませんが、2つの提案があります。

CustomView1 *CustomView = [[CustomView1 alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; 
[self.viewController.view addSubview:CustomView]; 

または

2に

1)変更

CustomView1 *CustomView = [[CustomView1 alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.viewController.view = CustomView; 

)トップビューに移動を参照します.xibファイルの両方で、カスタムクラスを使用するように変更。次に、あなただけの

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease]; 
    } else { 
     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease]; 
    } 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

通常

enter image description here

サイドノートのようなアプリの起動をさせることができます。 あなたが大文字で始まる変数の命名は避けるべきです。多くのコーディング標準では、クラスは大文字で始まり、変数は小文字で始まります。

+0

ワンダフル! ^^。あなたの提案は正しく機能します。 –

+0

アドバイスありがとうございます(サイドノード) –

0

1つのビュークラスを管理するために2つの異なるビューコントローラが必要な場合は、ビューコントローラがloadViewメソッドまたはnibファイルで正しいビュークラスをロードするようにする必要があります。私はあなたのコードのコントローラがペン先を使用していると思います。その場合は、nibsを編集してビュークラスをCustomView1に設定します。

CustomView1は何も意味しないので、クラス名IMHOの不幸な選択です。

+0

問題は解決しました。ご関心をお寄せいただきありがとうございます。 –

関連する問題