如何实现loadView?
我创建了一个名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有为 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)];
我需要在
loadView
中将背景色设置为白色I need to make the background color white in
loadView