Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CMT

macrumors regular
Original poster
Aug 24, 2009
102
10
Probably the error is silly, but I can't make this work.

I've subclassed an UIView and added two fields: 1 CGPoint and 1 CGFloat. I know this is not all MVC compliant, but I just don't want to create a model object for this.

The problem is that when I want to use them in drawRect:, both are null.

No errors or messages in the console.

Code:
@interface DotView : UIView {

    CGPoint center;
    CGFloat radius;
}

@end


@implementation DotView

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        
        center = CGPointMake(50.0, 50.0);
        radius = 10.0;
    }
    return self;
}

@end

Thanks!
 

ulbador

macrumors 68000
Feb 11, 2010
1,554
0
I vaguely remembered beating my head against my desk a year or two ago dealing with the same issue. :)
 

firewood

macrumors G3
Jul 29, 2003
8,107
1,345
Silicon Valley
I can never remember which init/awake/willshow gets called first. So I just add a Boolean to my instance variables; if I find that it's 0 in any call to drawRect (the first), init my graphic rects/points/colors/whatevers or call my initializer methods there, then set the Boolean to true. Works even if I keep switching view instantiation back and forth between programatic and nib during development/reuse.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.