我创建了一个名为GraphView
的自定义视图。加载视图时,我得到的只是一个空白的黑屏。这是我的代码:
:
@synthesize graphView, graphModel;
- (void)loadView
{
GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
self.view = aGraphView;
self.graphView = aGraphView;
[aGraphView release];
}
当我尝试在loadView
GraphViewController.m
时,我不确定为什么会出现黑屏
答案 0 :(得分:2)
您没有为GraphView
对象设置框架:
GraphView *aGraphView = [[GraphView alloc] init];
UIView
的指定初始值设定项为-initWithFrame:
。做这样的事情(根据需要设置视图的大小/原点):
GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
答案 1 :(得分:2)
我需要在loadView
- (void)loadView
{
GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
aGraphView.backgroundColor = [UIColor whiteColor];
self.view = aGraphView;
self.graphView = aGraphView;
[aGraphView release];
}