I have a text field. If it has wrong values then it may show the alert values and also make the text field empty, but when I use:
textField.text = @"";
after alertView my app hangs and crashes with EXC_BAD_ACCESS.
but when i use textField.text = @"1"; then it works fine, but I want the text field to be empty. How do I do this?
-(void)textFieldTextDidChangeClinicMarkup:(UITextField*)tf{
NSString*test=clinicMarkupTextField.text;
if([test isEqualToString:@"1"]) {
NSString*value=@"1";
appDelegate.clinicalMarkup=value;
}
else if([test isEqualToString:@"1.5"]){
NSString*value=@"1.5";
appDelegate.clinicalMarkup=value;
}
else if([test isEqualToString:@"2"]){
NSString*value=@"2";
appDelegate.clinicalMarkup=value;
}
else if([test isEqualToString:@"2.5"]){
NSString*value=@"2.5";
appDelegate.clinicalMarkup=value;
}
else if([test isEqualToString:@"3"]){
NSString*value=@"3";
appDelegate.clinicalMarkup=value;
}
else if([test length] >=3 || [test floatValue] > 3 || [test floatValue] <1 ) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Clinic Markup can only be $1, $1.5, $2, $2.5 and $3 " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
clinicalMArkupTextfield.text=@"";
}
}
This function is might be called because of you have registered it for text change notification.
While you assign blank value by above line, this function will be called again (due to text change notification). Now, none of your condition is satisfied, so it will again come to last else if statement. And it might fall in infinite loop and create a probable crash.
Otherwise, there seems to be nothing wrong.