为什么我看到黑屏?我没有分配东西吗? [英] Why am I seeing a black screen? Did I not alloc something?

查看:105
本文介绍了为什么我看到黑屏?我没有分配东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在xcode中,这是我创建的一个视图:

In xcode, this is one of the views I have created:

如果我在模拟器中运行程序,我可以看到这个视图很好。但是,如果我创建一个UIViewController类并使用此视图挂钩(我确认此视图是一个UIViewController),这就是我在模拟器中得到的结果:

If I run the program in the simulator, I can see this view fine. However, if I create a UIViewController class and hook it up with this view (I confirmed this view is a UIViewController), this is what I get in the simulator:

< img src =https://i.stack.imgur.com/vTL32.pngalt =在此处输入图像说明>

为什么我这样做屏幕?如何获得看起来像第一张图像的屏幕?

Why do I get this blank screen? How can I get the screen that looks like the first image?

编辑:代码

#import "EnterLevelViewController.h"

@interface EnterLevelViewController ()

@end

@implementation EnterLevelViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)loadView
{
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end


推荐答案

从代码中可以看出,您已从视图控制器中取消注释 - (void)loadView 方法,该方法在模板中提供。执行此操作时,控制器将尝试以编程方式构建视图,而不是使用nib(故事板)。完全删除空方法,看看是否有帮助。

It appears from your code that you have uncommented the -(void)loadView method from the view controller, which is provided in the template. When you do this, the controller will try to construct the view programmatically, instead of using the nib (storyboard). Remove the empty method completely and see if that helps.

这篇关于为什么我看到黑屏?我没有分配东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆