Question

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...

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top