I have a UIView which has several buttons added to it as subviews. Currently I have the buttons in drawRect:, which I have heard is a bad idea because drawRect can be called several times. I tried to move these UIButtons to initWithFrame, but they just don't get drawn. How should I fix this?
I am not using interface builder, so there are no NIB files present. The initWithFrame is called. I checked by adding an NSLog(...), and my NSMutableArrays are being properly initialized.
My initWitFrame: code currently has very little. It is
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
results = [[NSMutableArray alloc] init];
inputs = [[NSMutableArray alloc] init];
format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"EEE, MMM dd, yyyy"];
renc =[[RenameController alloc] init];
}
return self;
}
I have tried to add a textlabel like the following
#define BOX_WIDTH 155.0
#define BOX_OFFSET 45.00
#define ROW_HEIGHT 27
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
results = [[NSMutableArray alloc] init];
inputs = [[NSMutableArray alloc] init];
format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"EEE, MMM dd, yyyy"];
renc =[[RenameController alloc] init];
double row=0.0;
[self makelabel:@"Start" at:CGRectMake(0, row, BOX_OFFSET, ROW_HEIGHT)];
}
return self;
}
-(void) makelabel:(NSString *) str at:(CGRect) rect
{
UILabel *title = [[UILabel alloc] initWithFrame:rect];
title.text = str;
title.textAlignment = UITextAlignmentLeft;
title.textColor = [UIColor blackColor];
title.backgroundColor = [UIColor clearColor];
title.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
[self addSubview:title];
[title release];
}