7

大家好,我正在尝试为每个文本字段嵌入图像......当我将文本插入第一个文本字段时,图像也会对第二个文本字段产生影响。我会在用户选择的每个文本字段中显示图像,而不是直接显示给所有人...我在哪里做错了?

谢谢大家

-(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;
}
4

1 回答 1

5

所有文本字段都会触发此方法。您应该在 if 语句中使用参数“textField”来确定发件人的身份。

if( [textField isEqual: FF_NomeCognomeTexfield] == YES){
    ...
}
于 2013-10-02T15:26:30.397 回答