views:

21

answers:

1

i was trying out quartz 2d today and i got to learn basic drawing and other things, but now, somehow everything i do doesn't draw a thing on the iphone screen! i tried making a new project and starting from scratch but still no luck... first, i made a new view based application, and then created a new file (.h and .m) as a subclass of UIView. In the implementation, i just overrode the drawRect method, and nothing happens! heres the code:

    - (void)drawRect:(CGRect)rect {

 CGContextRef context = UIGraphicsGetCurrentContext();

 CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};

 CGContextSetStrokeColor(context, red);
 CGContextBeginPath(context);
 CGRect rectangle = CGRectMake(0, 0, 400, 200);
 CGContextAddRect(context, rectangle);
 CGContextSetFillColor(context, red);
 CGContextFillPath(context);
}

i have another project that i started before and have the exact same code in and that runs perfectly... so i think i changed some settings or something.. can anyone help?

EDIT: there is nothing i forgot, im sure of it, since i've been doing what i did in my last project, but somehow, it doesnt draw in this one...

A: 

I usually forget to set the class of the custom view in Interface Builder (Class popup at the top of the Identity page of the Inspector window). That would explain why drawRect: isn't called.

Codo
What do you mean by custom view? do you mean the viewcontroller that xcode creates or do you mean the subclass of UIView that i created?
retsrif
By _custom view_, I mean the subclass of _UIView_ that you created.
Codo
thanks!! it worked! though i dont know why i never needed to do this before...
retsrif