user1028028 user1028028 - 1 month ago 5
iOS Question

Password confirmation with 2 UITextFields

I want the user to confirm the password he typed it... so I use two text fields.. But somehow even if both have the same password it seems to think that the 2 strin differ

if (![self.typePTextField.text isEqualToString:self.retypePLabel.text]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"Error") message:NSLocalizedString(@"Passwords do not match \n please retype", @"Passwords do not match \n please retype") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
self.typePTextField.text = @"";
self.retypePLabel.text = @"";
return;
}


The alert appears even if I type the same string twice... and only the first text field geets reset to @"" ...
What will fix this?

Answer

I'm guessing in the isEqual: method

self.retypePLabel.text

should be

self.retypePTextField.text