比较两个文本字段的文本
如何比较两个文本字段中的文本以查看它们是否相同,例如在“密码”和“确认密码”文本字段中?
if (passwordField == passwordConfirmField) { //they are equal to each other } else { //they are not equal to each other }
你试过这个吗?
if ([passwordField.text isEqualToString:passwordConfirmField.text]) { //they are equal to each other } else { //they are not equal to each other }
你可以通过使用NSString的isEqualToString:方法来做到这一点:
NSString *password = passwordField.text; NSString *confirmPassword = passwordConfirmField.text; if([password isEqualToString: confirmPassword]) { // password correctly repeated } else { // nope, passwords don't match }
希望这可以帮助!