drawRect gets called on UIView subclass but not on UIViewController

Posted by HotFudgeSunday on Stack Overflow See other posts from Stack Overflow or by HotFudgeSunday
Published on 2011-05-11T20:54:50Z Indexed on 2012/11/14 5:00 UTC
Read the original article Hit count: 222

My code is working so far but I had to create a Class for the UIView. This is a bit inconvenient because I need to interact with the ViewController too.

BTW, I did try [self setNeedsDisplay] on the ViewDidLoad of the UIViewController subclass file but it didn't work.

Here's the code, which works on UIView Subclass but doesn't get called on a UIViewController one:

- (void)drawRect:(CGRect)rect
{
    UIColor *currentColor = [UIColor redColor];

    CGContextRef context = UIGraphicsGetCurrentContext();

    someNum = 1;
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, 30, 40);
    [self addDotImageX:30 andY:40];

    CGContextSetLineWidth(context, 2);
    CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
    CGContextStrokePath(context);
}

Any ideas on what to try? BTW, this is a TabBar App. I know those can somehow block the calls to drawRect.

The Tabs where created programatically, not through a Nib. Eg:

NSMutableArray *listOfViewControllers = [[NSMutableArray alloc] init];
UIViewController *vc;

vc = [[Education alloc] init];
vc.title = @"Education";
[listOfViewControllers addObject:vc];
vc.tabBarItem.image = [UIImage imageNamed:@"info.png"];
[vc release];

I would appreciate any ideas. I've been through the answers on this site related to setNeedsDisplay not calling drawRect and haven't found an answer for my particular case.

Thanks.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa-touch