I have a text box in an app i am making. The user inputs a number into the text box and it does some stuff from there. Anyways, I want the user to only input numbers 1-12, not higher. How should I input code so that if they inputted a number higher then 12, then an alert message pops up and tells them to put a number lower then 12 in. I have attempted and failed with this code:
Code:
-(void)sidesOfPolygons:(id)sender{
NSString *msg = nil;
if (polygonsSides.text > 12)
msg = @"Please choose a number between 1 and 12.";
NSLog(@"MSG worked, moving on to the alert.");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Area of Polygons"
message:msg
delegate:self
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
}
I would also like the text box to clear after the message.
Any help is greatly appreciated.
Thanks,
kiambogo
__________________
Math Tools - Geometry (Coming Soon)
I may be wrong, but i dont think you can see if a number (int) is less than a label, because the label isnt an int.
do something like this:
Code:
int pSides = polygonsSides.text;
-(void)sidesOfPolygons:(id)sender{
NSString *msg = nil;
if (pSides > 12)
msg = @"Please choose a number between 1 and 12.";
NSLog(@"MSG worked, moving on to the alert.");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Area of Polygons"
message:msg
delegate:self
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
}
I get two warnings though. First, is about the 'int pSides = polygonsSides.text'
The message says "warning: initializaition makes integer from pointer without a cast." the second message is about 'otherButtonTitles:nil];' the message is "warning: no '-initWithTitle:message:delegatetherButtonTitles:' method found"
Any help to solve these problems is appreciated.
Thanks,
kiambogo
__________________
Math Tools - Geometry (Coming Soon)
Thanks for the input. This has helped me quite a bit. However, I am still stuck trying to figure out how to set a string as a value of integers between 12 and 100. I just need to know what to put. As of now, I have this: