开发者

How to implement loadView?

I've created a custom view called GraphView. All I get is a blank black screen when the view is loaded开发者_如何学Python. 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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜