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

Monday, 13 January 2014

Create Customize ActivityIndicatorView

   .h file

@interface RootViewController : UIViewController {
UIActivityIndicatorView *activityView;
UIView *loadingView;
UILabel *loadingLabel;
}
@property (nonatomic, retain) UIActivityIndicatorView * activityView;

@property (nonatomic, retain) UIView *loadingView;
@property (nonatomic, retain) UILabel *loadingLabel;

.m file

#import <QuartzCore/QuartzCore.h>

@synthesize activityView;
@synthesize loadingView;
@synthesize loadingLabel;

  loadingView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
     loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
     loadingView.clipsToBounds = YES;
     loadingView.layer.cornerRadius = 10.0;
     activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
     activityView.frame = CGRectMake(65, 40, activityView.bounds.size.width, activityView.bounds.size.height);
    [loadingView addSubview:activityView];
    loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    loadingLabel.backgroundColor = [UIColor clearColor];
    loadingLabel.textColor = [UIColor whiteColor];
    loadingLabel.adjustsFontSizeToFitWidth = YES;
    loadingLabel.textAlignment = UITextAlignmentCenter;
    loadingLabel.text = @"Loading...";
    [loadingView addSubview:loadingLabel]; 
    [self.view addSubview:loadingView];

[activityView startAnimating];

[activityView stopAnimating];

[loadingView removeFromSuperview];

Tuesday, 7 January 2014

How to pass button tag value one controller to another controller

First controller:

    button_name.tag = value;

    NSInteger theInteger =  button_name.tag;


   Second_controller *next = [[Second_controller alloc]ini];
   [next setMyInteger:theInteger];
   [self.navigationController pushViewController:next animated:YES];

Second controller:

@property(nonatomic) NSInteger myInteger;