1

I having some problems with drawRect and create a new instance of a UIView custom class.

My question is: How can i use of drawrect? I created a UIViewController with a UIScrollView and inside this UIScrollView about 50 UIViews. Each UIView create inside 3 elements (Custom UIViews) each one with a drawrect:

- (void)drawRect:(CGRect)rect 
{
    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextClearRect(c, self.bounds);

    CGContextSetStrokeColorWithColor(c, color.CGColor);
    CGContextSetLineCap(c, kCGLineCapRound);
    CGContextSetInterpolationQuality(c, kCGInterpolationHigh);

    CGContextSetLineWidth(c, thickness);
    CGContextAddArc(c, self.frame.size.width/2, self.frame.size.height/2, radius, angleIni*M_PI/180, angleEnd*M_PI/180, 0);
    CGContextStrokePath(c);
}

At first it works like a charm, but when i try to remove this UIViewController and Create it again I'm getting a EXC_BAD_ACCESS.

If I remove the drawrect code everything begin to work again with no EXC_BAD_ACCESS. So I conclued tha my problem ismy drawrect method.

Is there some right way to true remove my UIviewController? On dealloc I'm removing all my UIViews inside UIScrollView and setting it to nil, besides I'm setting UIScrollView to nil too, like:

for (UIView *item in MyUICscrollView.subviews)
{
  [item removeFromSuperview];
  item = nil;
}
MyUICscrollView = nil;

Had someone the same issue?

0 Answers0