4

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

ladookie
  • 1,343
  • 4
  • 21
  • 24

2 Answers2

2

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

indragie
  • 18,002
  • 16
  • 95
  • 164
  • I made the indicated changes and it still just shows a blank black screen. – ladookie Mar 14 '11 at 02:19
  • I commented out `loadView` and now it works even though I deleted the .xib file that I was using before. I'm confused as to how it could work without a .xib or a `loadView` – ladookie Mar 14 '11 at 02:29
  • You need to clean the deployed app as well. Delete the application on the simulator or device. Clean all targets. Run application. Then you'll see how its working. –  Mar 14 '11 at 02:32
  • how do I 'clean all targets, etc.' ? – ladookie Mar 14 '11 at 02:34
  • Okay I made a new project and copied the files and now when I comment out loadView I get a blank white screen. If i Implement loadView, then I get a blank black screen. I'll post my `graphView.m` – ladookie Mar 14 '11 at 02:46
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];
}
ladookie
  • 1,343
  • 4
  • 21
  • 24