我将现有项目的应用程序委托修改为默认为标准应用程序委托,并使其在启动后将自定义视图控制器的视图添加到场景中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
SplashScreenController *controller = [[SplashScreenController alloc] init];
[self.window addSubview:controller.view];
return YES;
}
我不明白的是,为什么我的观点不显示?加载后屏幕始终为perma-black,因为我确实可以看到视图确实加载了:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(@"View did load.");
}
答案 0 :(得分:2)
我很难理解你要做的事情,但看起来你的意思是设置你的窗口的根视图控制器。试试这个:
SplashScreenController *controller = [[SplashScreenController alloc] initWithNibName:@"theNibName" bundle:nil];
[self.window setRootViewController:controller];
答案 1 :(得分:0)
我明白了。我没有在视图控制器中分配窗口,也没有使窗口键和可见。代码应该在委托中如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
SplashScreenController *controller = [[SplashScreenController alloc] init];
[self.window addSubview:controller.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}