我正在尝试从 UIViewController 在 AppDelegate 的 UIWindow 中添加 UILabel。这就是我这样做的方式:
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;
}
视图控制器代码:
- (void)viewDidLoad
{
UILabel *abcd=[[UILabel alloc] initWithFrame:CGRectMake(100.0, 100.0, 200.0, 40.0)];
abcd.text=@"loading...";
abcd.backgroundColor=[UIColor clearColor];
[[[[UIApplication sharedApplication] delegate] window] addSubview:abcd];
[super viewDidLoad];
}
但我所看到的只是灰屏,但没有标签。我可能哪里出错了?