Delegado UITextField personalizado configurado para autoinicia el bucle infinito

Estoy escribiendo una aplicación para iPhone en la que necesito la clase personalizada UITextField. Para mis campos de texto necesito sangría, imagen dentro del texto y caracteres máximos. Por esta razón, creé una clase personalizada basada en UITextField. Todos mis campos de texto se basarán en esta nueva clase. Utilizo Google y busqué Stackoverflow y encuentro que en casos como el mío tengo que usarself.delegate = self; durante elinit así que no necesito implementar métodos comotextFieldShouldBeginEditing otextFieldShouldEndEditing dentro de mi clase de controlador de vista. Todos mis campos de texto se crearán en el guión gráfico.initWithCoder. Como resultado, recibo un bucle infinito y un bloqueo de la aplicación (uso el simulador en este momento) después de escribir 1, 2 o 3 símbolos. Es interesante que para el teclado numérico o el teclado de contraseña no haya tal problema. Además, si escribo símbolos en mi teclado Mac en su lugar en el simulador, no hay problema. Intenté depurar, pero durante el bloqueo salta directamente al bucle y existe con error. ¿Como superar este problema?

PD Yo preguntépregunta cuando recibo bucle infinito y hubo comentarios queself.delegate = self; puede causar tal bucle, pero veo que esta declaración es ampliamente utilizada. Puede que no haya hecho esto correctamente, pero no puedo entender cómo hacer que la clase reutilizable de UITextField.

EDITAR: Aquí está mi código:

En inti inicializo y configuro el color del borde:

- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {

        self.layer.borderColor=[[UIColor blackColor] CGColor];
        self.delegate = self;
    }
    return self;
}

Cuando comienzo a editar, cambio el color del borde y establezco la sangría (el conjunto de sangría se moverá en el configurador de propiedades):

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    // Change border of text field that is editing to orange
    textField.layer.masksToBounds=YES;
    textField.layer.borderColor=[[UIColor orangeColor] CGColor];
    textField.layer.borderWidth= 1.0f;

    UIView *spacerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _leftIndent, 10)];
    [self setLeftViewMode:UITextFieldViewModeAlways];
    [self setLeftView:spacerView];

    return YES;
}

Al finalizar la edición, regreso el color:

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{

    // Change border of text field that is edited to black
    textField.layer.masksToBounds=YES;
    textField.layer.borderColor=[[UIColor blackColor] CGColor];
    textField.layer.borderWidth= 1.0f;

    return YES;
}

Y en el cambio de valor verifico caracteres máximos:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    // Restrict number of symbols in text field to "maxSymbols"
    NSUInteger oldLength = [textField.text length];
    NSUInteger replacementLength = [string length];
    NSUInteger rangeLength = range.length;

    NSUInteger newLength = oldLength - rangeLength + replacementLength;

    BOOL returnKey = [string rangeOfString: @"\n"].location != NSNotFound;

    return newLength <= (int)_maxSymbols || returnKey;
}

Respuestas a la pregunta(1)

Su respuesta a la pregunta