大家好我正在尝试为每个文本域嵌入图像... 当我将文本插入第一个文本字段时,图像也会对第二个文本字段产生影响。我想用visualizzassero为用户选择的每个文本域而不是直接对所有人进行图像...我在哪里做错了?
感谢所有
-(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;
}
答案 0 :(得分:5)
所有textField都会触发此方法。您应该在if语句中使用参数'textField'来确定发件人的身份。
if( [textField isEqual: FF_NomeCognomeTexfield] == YES){
...
}