J'ai un UIView qui a plusieurs boutons ajoutés comme sous-vues. Actuellement, j'ai les boutons dans drawRect :, ce que j'ai entendu est une mauvaise idée parce que drawRect peut être appelé plusieurs fois. J'ai essayé de déplacer ces UIButtons vers initWithFrame, mais ils ne sont pas dessinés. Comment devrais-je résoudre ce problème?UIView drawRect vs initWithFrame
Je n'utilise pas de programme de création d'interface. Par conséquent, aucun fichier NIB n'est présent. Le initWithFrame est appelé. J'ai vérifié en ajoutant un NSLog (...), et mes NSMutableArrays sont correctement initialisés.
Mon initWitFrame: code a actuellement très peu. Il est
- (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;
}
J'ai essayé d'ajouter un Textlabel comme le
suivant#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];
}
OK, alors pouvez-vous votre part initWithFrame: Code? Est-ce que initWithFrame: est appelé? – tonklon
Ajout du code. Je ne pense pas que ce soit si utile –
Ce code n'affiche aucun bouton créé ou ajouté à la vue. Pourriez-vous publier le code dans lequel vous avez tenté de les ajouter à la vue dans -initWithFrame :? –