How to implement loadView?

我的未来我决定 提交于 2019-12-07 12:37:01

问题


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


回答1:


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)];




回答2:


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];
}


来源:https://stackoverflow.com/questions/5293976/how-to-implement-loadview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!