如何实现loadView?

发布于 2024-10-21 11:54:48 字数 417 浏览 8 评论 0原文

我创建了一个名为 GraphView 的自定义视图。加载视图时我得到的只是一个空白的黑屏。这是我的代码:

在 GraphViewController.m 中:

@synthesize graphView, graphModel;

- (void)loadView
{   
    GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
    self.view = aGraphView;
    self.graphView = aGraphView;

    [aGraphView release];
}

我不确定为什么当我尝试在 GraphViewController.m 中实现 loadView 时出现黑屏

I've created a custom view called GraphView. All I get is a blank black screen when the view is loaded. Here is my code:

in GraphViewController.m:

@synthesize graphView, graphModel;

- (void)loadView
{   
    GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
    self.view = aGraphView;
    self.graphView = aGraphView;

    [aGraphView release];
}

I'm not sure why I just get a black screen when I try to implement loadView in GraphViewController.m

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉南桥 2024-10-28 11:54:48

您没有为 GraphView 对象设置框架:

GraphView *aGraphView = [[GraphView alloc] init];

UIView 的指定初始值设定项是-initWithFrame:。执行如下操作(根据需要设置视图的大小/原点):

GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

You're not setting a frame for the GraphView object:

GraphView *aGraphView = [[GraphView alloc] init];

The designated initializer for UIView's is -initWithFrame:. Do something like this (setting the size/origin of the view as you desire):

GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

零度° 2024-10-28 11:54:48

我需要在 loadView 中将背景色设置为白色

- (void)loadView
{   
    GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
    aGraphView.backgroundColor = [UIColor whiteColor];
    self.view = aGraphView;
    self.graphView = aGraphView;

    [aGraphView release];
}

I need to make the background color white in loadView

- (void)loadView
{   
    GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
    aGraphView.backgroundColor = [UIColor whiteColor];
    self.view = aGraphView;
    self.graphView = aGraphView;

    [aGraphView release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文