In my app, i have two textfields(username and Password) and UIbutton in SignIn page.
I want to enable button if textfield(password) having text.
I have created the UITextfield and UIbutton with below property in viewDidLoad().
self.txtFieldPassword.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.btnLogin setEnabled:NO];
I have tried the below code and there is no luck.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField == self.txtFieldPassword) {
// checking for any whitespaces
if(([string rangeOfString:@" "].location != NSNotFound))
{
return NO;
}
if( [[self.txtFieldPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] )
self.btnLogin.enabled = YES;
else
self.btnLogin.enabled = NO;
}
return YES;
}
but, if i removed the below line in UitextField means, it have worked.
self.txtFieldPassword.clearButtonMode = UITextFieldViewModeWhileEditing;
i want to enable button with the above property. How to achieve it?
Thanks!!!