Xcode 4.5 と iOS 6.0 を使用しています。xcode からデフォルトのシングル ビュー テンプレートを選択しました。アプリケーション ウィンドウにラベルを追加したいだけですが、それができません。私を修正してください。
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)];
label.text = @"Test";
[label setBackgroundColor:[UIColor whiteColor]];
[self.window addSubview:label];
[self.window bringSubviewToFront:label];
[self.window makeKeyAndVisible];
return YES;
}
PS - ViewController ビューの上、つまりウィンドウ上にラベルを配置したいので、ウィンドウによって表示されるビューが変更されても、ラベルは常にそこに表示されます。ここにラベルだけを表示したくありません。
私は答えを得た
[self.window.rootViewController.view addSubview:label];
ポインタを与えてくれてありがとう。