Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextField Custom for Validate

Hello everyone I'm trying to embed images for each textfield ... When I go to insert the text into the first textfield, the image also has an impact on the second textfield. I would that images visualizzassero each textfield that the user selects and not directly to all ... Where am I doing wrong?

Thanks to all

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField   {
    NSString *nomecognome = self.FF_NomeCognomeTexfield.text ;
    NSString *user = self.FF_UsernameTextField.text ;

    if ([nomecognome length] == 0 || [user length] == 0  ){

        FF_NomeCognomeTexfield.leftViewMode = UITextFieldViewModeAlways;

        UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
        imageView.image = [UIImage imageNamed:@"FF_CheckOFF"];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        FF_NomeCognomeTexfield.leftView = imageView;

        FF_UsernameTextField.leftViewMode = UITextFieldViewModeAlways;
        UIImageView* imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
        imageView1.image = [UIImage imageNamed:@"FF_CheckOFF"];
        imageView1.contentMode = UIViewContentModeScaleAspectFit;
        FF_UsernameTextField.leftView = imageView1;
    } else {
        FF_NomeCognomeTexfield.leftViewMode = UITextFieldViewModeAlways;
        UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
        imageView.image = [UIImage imageNamed:@"FF_CheckON"];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        FF_NomeCognomeTexfield.leftView = imageView;

        FF_UsernameTextField.leftViewMode = UITextFieldViewModeAlways;
        UIImageView* imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
        imageView1.image = [UIImage imageNamed:@"FF_CheckON"];
        imageView1.contentMode = UIViewContentModeScaleAspectFit;
        FF_UsernameTextField.leftView = imageView1;
    }
    return YES;
}
like image 985
kAiN Avatar asked Sep 22 '13 19:09

kAiN


1 Answers

All textFields trigger this method. You should use the argument 'textField' in an if-statement to determine the identity of the sender.

if( [textField isEqual: FF_NomeCognomeTexfield] == YES){
    ...
}
like image 133
bbaassssiiee Avatar answered Oct 02 '22 05:10

bbaassssiiee