I have a button and when its clicked/tapped I want to check that a text box has a value. If no value is present I want an alert to pop up. The button loads a second ViewController which displays waypoints on a google map, if no option is in the text box the google maps ViewController will have problems loading the waypoints as it wont know which objects to request from the database.
I’ve been playing around with the code below:
-(IBAction)mapButton
{
if (route.text == NULL)
//if (route.text == [NSNull null])
//if ([route.text isEqual:[NSNull null]])
{
mapViewController .sharedMapID=mapID;
[self presentModalViewController:mapViewController animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Please select a route !" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Firstly, isn’t that
ifthe wrong way around? I thought you said that you wanted the UIAlert to appear if there was no text, not if it there was (route.text == null)…?Secondly, have you tried just checking for an empty string (
route.text.length == 0) instead of null? (Disclaimer – no idea about iPhone development…)