UIViewControllerからAppDelegateのUIWindowにUILabelを追加しようとしています。AppDelegate別のviewControllerのUIWindow addSubView
AppDelegateコード:
- (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 makeKeyAndVisible];
self.window.rootViewController = self.viewController;
return YES;
}
のViewControllerコード:これは私がこれをやっている方法です
- (void)viewDidLoad
{
UILabel *abcd=[[UILabel alloc] initWithFrame:CGRectMake(100.0, 100.0, 200.0, 40.0)];
[email protected]"loading...";
abcd.backgroundColor=[UIColor clearColor];
[[[[UIApplication sharedApplication] delegate] window] addSubview:abcd];
[super viewDidLoad];
}
しかし、私は見ていますすべてが灰色の画面が、ラベルなしです。どこが間違っているかもしれない?
ちょっとしたヒントは、特定のiPadまたはiPhoneビューを読み込むためにアプリがiPadで動作していることを確認する必要はありません。ビューの名前に '〜ipad'を追加するだけです。したがって、iphoneビューのファイル名は 'ViewController.xib'になり、iPadのバージョンは' ViewController〜ipad.xib'になります。これでビューをロードすることができます: '[[ViewController alloc] initWithNibName:@" ViewController "bundle:nil]'とiOSが正しいものをロードします。 – rckoenes
ああ...チップをありがとう。 :)答えてください。 :) – Nitish