Estoy agregando dos subvistas, que están almacenadas por propiedades, a mi vista. Al agregar las subvistas a mi vista, las subViews se desasignan aparentemente después de llamar a mi método setup
. El resultado final es que las vistas nunca se muestran. Ahora, si cambio mis propiedades a strong
en lugar de weak
, conservo una referencia a las vistas y ahora se muestran en la pantalla. Entonces, ¿qué está pasando aquí? ¿Por qué el addSubview:
y el insertSubview:
no conservan las subvistas? Ver el código de abajo:¿Por qué addSubview no conserva la vista?
por cierto, estoy usando IOS5 con ARC (de ahí el material fuerte y débil)
#import "NoteView.h"
@interface NoteView() <UITextViewDelegate>
@property (weak, nonatomic) HorizontalLineView *horizontalLineView; // custom subclass of UIView that all it does is draw horizontal lines
@property (weak, nonatomic) UITextView *textView;
@end
@implementation NoteView
@synthesize horizontalLineView = _horizontalLineView;
@synthesize textView = _textView;
#define LEFT_MARGIN 20
- (void)setup
{
// Create the subviews and set the frames
self.horizontalLineView = [[HorizontalLineView alloc] initWithFrame:self.frame];
CGRect textViewFrame = CGRectMake(LEFT_MARGIN, 0, self.frame.size.width, self.frame.size.height);
self.textView = [[UITextView alloc] initWithFrame:textViewFrame];
// some addition setup stuff that I didn't include in this question...
// Finally, add the subviews to the view
[self addSubview:self.textView];
[self insertSubview:self.horizontalLineView atIndex:0];
}
- (void)awakeFromNib
{
[super awakeFromNib];
[self setup];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}
¿Cómo va a crear la instancia de NoteView? ver de control está llegando en la configuración .. –
Estoy creando la instancia de NoteView agregándola a un controlador de vista en un guión gráfico. –
¿Está su clase especificada en Xib como NoteView –