I have five fields for number input, and each of these fields must be in a certain number range. For example, Field One should be above 40 and below 100. Field Two should be above 1.25 and below 5.5. You get the idea for the rest.
I am able to make an UIAlertView, but only for the button that is pressed to calculate each of the fields. If the end-user inputs wrong data for each of the five fields, they will then see five different Alerts and isn't really UI friendly.
I would like to have it where the user inputs the number, and when the user goes to the next field, to evaluate their input and then send an Alert View. This way the user would automatically know before they input another field. I think this would work much easier for the UI. But, I don't know the best way to do this and I'm just learning iPhone SDK and ObjC.
Here is my code I have used for my buttonPressed button, which as you can see takes each of the five (four in this case) fields, assigns them to a variable, creates two test UIAlerts, and does some math before outputting the answer. Keep in mind I'm a n00b here.....
//calculate total of variables when user clicks button
-(IBAction) submitYourName;
{
/*********************************************************
declare our variables to strings
********************************************************/
NSString *userNameOne = txtUserName.text;
float numOne = [userNameOne intValue];
NSString *userNameTwo = txtUserName2.text;
float numTwo = [userNameTwo intValue];
NSString *userNameThree = txtUserName3.text;
float numThree = [userNameThree intValue];
NSString *userNameFour = txtUserName4.text;
float numFour = [userNameFour intValue];
/*********************************************************
allow error handling for our numbers
********************************************************/
if(numOne < 40 || numOne > 100)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"User Error"
message:@"Your age must be at least 40 years old and less than 100 years old"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
if(numTwo < 40 || numTwo > 100)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"User Error"
message:@"Your age must be at least 40 years old and less than 100 years old"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
/*********************************************************
calculate our mathematics
********************************************************/
float one = 3;
float main = numOne * one;
/*********************************************************
produce answer
********************************************************/
lblUserTypedName.text = [[NSString alloc] initWithFormat: @"you input %2.2f %2.2f %2.2f %2.2f", main, numTwo, numThree, numFour];
}