Creo una vista personalizada en cocoa touch que está superclasificada por UIView y en mi controlador principal la inicializo y luego la agrego como subvista a la vista principal, pero cuando la agrego a la vista principal llama a mi método de inicialización de nuevo y causa un bucle infinito. ¿Voy a crear mal mi vista personalizada? Aquí es el MAINVIEWCocoa Touch: Crear y agregar una vista personalizada
- (void)loadView {
UIImage* tempImage = [UIImage imageNamed: @"image1.jpg"];
CustomImageContainer *testImage = [[CustomImageContainer alloc] initWithImage: tempImage andLabel: @"test image" onTop: true atX: 10 atY: 10];
[self.view addSubview: testImage];
}
y la CustomImageContainer
-(CustomImageContainer *) initWithImage: (UIImage *)imageToAdd andLabel: (NSString *)text onTop: (BOOL) top atX: (int) x_cord atY: (int) y_cord{
UIImageView *imageview_to_add = [[UIImageView alloc] initWithImage: imageToAdd];
imageview_to_add.frame = CGRectMake(0, 0, imageToAdd.size.width, imageToAdd.size.height);
UILabel *label_to_add = [[UILabel alloc] init];
label_to_add.text = text;
label_to_add.alpha = 50;
label_to_add.backgroundColor = [UIColor blackColor];
label_to_add.textColor = [UIColor whiteColor];
[self addSubview: imageview_to_add];
self.frame = CGRectMake(x_cord, y_cord, imageToAdd.size.width, imageToAdd.size.height);
if (top) {
label_to_add.frame = CGRectMake(0, 0, imageview_to_add.frame.size.width, imageview_to_add.frame.size.height);
//[self addSubview: label_to_add];
}
else {
label_to_add.frame = CGRectMake(0,.2 * imageview_to_add.frame.size.height, imageview_to_add.frame.size.width, imageview_to_add.frame.size.height);
}
[self addSubview: label_to_add];
[super init];
return self;
}
Thansk esto era parte del problema, la otra parte era que lo tenía en loadView not viewDidLoad, pero esto ayudó muchísimo, muchas gracias – AgentRegEdit