开发者

Checking for empty text box

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];
    }

}


Try this:

if (route.text.length == 0)
{
     // empty string or nil string
}


Firstly, isn't that if the 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...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜