我有一个文本字段。如果它有错误的值,那么它可能会显示警报值并使文本字段为空,但是当我使用时:
textField.text = @"";
在 alertView 之后,我的应用程序挂起并因 EXC_BAD_ACCESS 而崩溃。
但是当我使用它时textField.text = @"1";
它工作正常,但我希望文本字段为空。我该怎么做呢?
-(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=@"";
}
}