Pergunta

I have a subclass from UITextField that I use in Interface Builder to build my view (so I set the class of this object to MyCustomTextField in directly in Interface Builder).

Now, I understood that when the view gets loaded, the initWithCoder: method of MyCustomTextField will be invoked, so that I can do some initialization stuff. However, I also found that the attributes that I set in Interface Builder using the Attribute Inspector are NOT initialized in the way I set them!

Does anyone know why this is the case and how I can manage to set the properties of the instance of MyCustomTextField to the values that I set in the Attribute Inspector in Interface Builder?

Foi útil?

Solução

Your are probably not calling [super initWithCoder:coder] from your custom override of this method. The data is loaded from nib archive into the UIView instance in this super implementation. The correct implementation should look like:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (nil != self) {
        // extra initialization code
    }
    return self;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top