views:

60

answers:

1

Hello,

I have a UIViewController and I would like it to call drawRect so i can draw on the view but nothing happens.

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
...code...
}

@end

and the implementation

#import "ViewController.h"


@implementation ViewController

-(void) drawRect:(CGRect) rect {
draw a pony
}

- (void)viewDidLoad {
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

But no pony gets drawn on the view when the app is run, what do i do wrong?

+1  A: 

The UIViewController don't have overridden message drawRect. You should create custom class derived from UIView and override message drawRect there.

You can override message (UIView *)view for UIViewController and return own custom UIView or in Interface Builder change class from UIView to own class.

Victor