尝试使用.nib加载视图控制器失败

时间:2017-05-02 13:58:22

标签: ios objective-c interface-builder xib nib

我已经通过新文件创建了一个视图控制器,我检查了创建笔尖选项,这没关系。我做了一个很好的IB布局,事情很棒。文件所有者链接到右侧ViewController,nib中的视图链接到文件所有者的视图插座。

现在,我尝试使用AppDelegate中的nib实例化此视图控制器。

TerminationViewController *terminatedVC = [[TerminationViewController alloc] initWithNibName:@"TerminationViewController" bundle:nil];
terminatedVC.view.hidden = NO;
[self.window.rootViewController presentViewController:terminatedVC animated:YES completion:nil];

没有错误,我看到黑屏。我究竟做错了什么?我还检查了笔尖的目标成员资格。

修改

self.window = [[[InterceptorWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];

TerminationViewController *terminatedVC = [[TerminationViewController alloc] initWithNibName:@"TerminationViewController" bundle:nil];
terminatedVC.view.hidden = NO;
[self.window.rootViewController presentViewController:terminatedVC animated:YES completion:nil];

// Wait for 10 seconds
double delayInSeconds = 10.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
    // Do something, next view controller.
}

1 个答案:

答案 0 :(得分:2)

调用[self.window makeKeyAndVisible];在applicationDidFinishLaunching中