Friday, 17 January 2014

TextField validation

-(BOOL)validateFname:(NSString*)name {    
    if ([name length ]== 0)  {
        return NO;
    }    
    return YES;

}

- (IBAction)btnSave_Clicked:(id)sender
{
    if(![self validateFname:nametxt.text]) {
        connectFailMessage = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Food items can not be empty!"  delegate: self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        connectFailMessage.tag = 1002;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(95,15,22, 22)]; 
        NSString *imgPath = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"button_cancel.png"]];
        UIImage *yourImage = [[UIImage alloc] initWithContentsOfFile:imgPath];
        [imageView setImage:yourImage];
        [yourImage release];
        [imgPath release];
        [connectFailMessage addSubview:imageView];
        [connectFailMessage show];
        UILabel *theTitle1 = [connectFailMessage valueForKey:@"_titleLabel"];
        [theTitle1 setFont:[UIFont fontWithName:@"Avenir bold" size:16]];
        [theTitle1 setTextColor:[UIColor redColor]];
        UILabel *theBody1 = [connectFailMessage valueForKey:@"_bodyTextLabel"];
        [theBody1 setFont:[UIFont fontWithName:@"Avenir" size:15]];
        [theBody1 setTextColor:[UIColor whiteColor]];
        
        return;
    }
}

No comments:

Post a Comment