here I try this code.......enter image description here I try this code...I want to disable a button while validating a username and password. if my username and password is correct then my button will enable...But I didn't get correct answer.
How to enable/disable a button while validating a button?
67 views Asked by Kavitha Madhu At
3
There are 3 answers
0
On
-(void)checkValidation
{
NSString *strUserName = [_txtUsername.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *strPassword = [_txtPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if([strUserName isEqualToString:@"YOURSTRING"] && [strPassword isEqualToString:@"YOURSTRING"])
{
// make your button enable
}
else
{
// make it disable
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
newString = [newString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[self performSelector:@selector(checkValidation) withObject:nil afterDelay:0.3];
return TRUE;
}
0
On
If you don't set delegate to your text field then set the delegate as follows
self.stext1.delegate = self;
self.stext2.delegate = self;
Then implement this function
-(void)enableDisableSave {
NSString * userName = @"kavitha";
NSString * password = @"kavitha";
if([userName isEqualToString:self.stext1.text] && [password isEqualToString:self.stext2.text]) {
self.sendBtn.enabled = YES;
} else {
self.sendBtn.enabled = NO;
}
}
It looks to me like
sbuttonis an IBAction, not an outlet. If so your code probably won't compile. You need to control-drag from your button into your code to create an IBOutlet for your button and use the outlet to enable/disable the button.