delegates

view.h

#import <UIKit/UIKit.h>


@interface ViewController : UIViewController<UITextFieldDelegate>

@property UILabel *firstLabel,*lastlabel,*genderLabel,*mobileLabel,*cityLabel,*emailLabel,*passwordLabel,*rePasswordLabel,*addressLabel;
@property UITextField *firstText,*lastText,*mobileText,*cityText,*emailText,*passwordText,*rePasswordText;
@property UISegmentedControl *userSeg,*genderSeg,*agreeSeg;
@property UIScrollView *userView,*existView,*loginView;
@property UITextView *addressTable;
@property UIButton *submitButton;

//existing user

@property UILabel *userNameLabel,*userPasswordLabel;
@property UITextField *usernameText,*userPasswordText;
@property UIButton *login;

@property UILabel *firstL,*lastl,*genderL,*mobileL,*cityL,*emailL;
@property NSMutableArray *ary,*addrry;
@property NSMutableDictionary *svng;

//- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;

@end

view.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor grayColor];
    [self UIElements];
   
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)UIElements
{
    self.ary=[[NSMutableArray alloc]init];
    
    self.userSeg=[[UISegmentedControl alloc]initWithItems:@[@"NEW USER",@"EXISTING USER"]];
    self.userSeg.frame=CGRectMake(40, 30, 220, 30);
    [self.userSeg addTarget:self action:@selector(userDetails) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.userSeg];
    
    self.userView=[[UIScrollView alloc]initWithFrame:CGRectMake(10, 100, 350, 700)];
    self.userView.contentSize=CGSizeMake(350, 1000);
  // self.userView.backgroundColor=[UIColor grayColor];
    [self.view addSubview:self.userView];

    self.existView =[[UIScrollView alloc]initWithFrame:CGRectMake(10, 100, 350, 700)];
    self.existView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.existView];
    
    //firstName
    self.firstLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 0, 100, 30)];
    self.firstLabel.text=@"First Name";
    self.firstLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.firstLabel];
    
    self.firstText=[[UITextField alloc]initWithFrame:CGRectMake(150, 0, 150, 30)];
    self.firstText.placeholder=@"FirstName";
    self.firstText.borderStyle=UITextBorderStyleBezel;
    self.firstText.delegate=self;
    self.firstText.clearsOnBeginEditing=YES;
    self.firstText.clearButtonMode=YES;
    [self.userView addSubview:self.firstText];
    
    //lastName
    self.lastlabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 50, 100, 30)];
    self.lastlabel.text=@"Last Name";
    self.lastlabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.lastlabel];
    
    self.lastText=[[UITextField alloc]initWithFrame:CGRectMake(150, 50, 150, 30)];
    self.lastText.placeholder=@"LastName";
    self.lastText.borderStyle=UITextBorderStyleBezel;
    self.lastText.delegate=self;
    self.lastText.clearButtonMode=YES;
    self.lastText.clearsOnBeginEditing=YES;
    [self.userView addSubview:self.lastText];
    
    //gender
    self.genderLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 100, 100, 30)];
    self.genderLabel.text=@"Gender";
    self.genderLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.genderLabel];
    
    self.genderSeg=[[UISegmentedControl alloc]initWithItems:@[@"Male",@"Female"]];
    self.genderSeg.frame=CGRectMake(150, 100, 150, 30);
    [self.userView addSubview:self.genderSeg];
    
    //mobile
    self.mobileLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 150, 100, 30)];
    self.mobileLabel.text=@"Mobile";
    self.mobileLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.mobileLabel];
    
    self.mobileText=[[UITextField alloc]initWithFrame:CGRectMake(150, 150, 150, 30)];
    self.mobileText.placeholder=@"Mobile";
    self.mobileText.borderStyle=UITextBorderStyleBezel;
    self.mobileText.delegate=self;
    self.mobileText.clearsOnBeginEditing=YES;
    self.mobileText.clearButtonMode=YES;
    [self.userView addSubview:self.mobileText];
    
    //city
    self.cityLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 200, 100, 30)];
    self.cityLabel.text=@"City";
    self.cityLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.cityLabel];
    
    self.cityText=[[UITextField alloc]initWithFrame:CGRectMake(150, 200, 150, 30)];
    self.cityText.placeholder=@"City";
    self.cityText.borderStyle=UITextBorderStyleBezel;
    self.cityText.delegate=self;
    self.cityText.clearButtonMode=YES;
    self.cityText.clearsOnBeginEditing=YES;
    [self.userView addSubview:self.cityText];
    
    //email
    self.emailLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 250, 100, 30)];
    self.emailLabel.text=@"Email";
    self.emailLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.emailLabel];
    
    self.emailText=[[UITextField alloc]initWithFrame:CGRectMake(150, 250, 150, 30)];
    self.emailText.placeholder=@"Email";
    self.emailText.borderStyle=UITextBorderStyleBezel;
    self.emailText.delegate=self;
    self.emailText.clearsOnBeginEditing=YES;
    self.emailText.clearButtonMode=YES;
    [self.userView addSubview:self.emailText];
    
    //password
    self.passwordLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 300, 100, 30)];
    self.passwordLabel.text=@"Password";
    self.passwordLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.passwordLabel];
    
    self.passwordText=[[UITextField alloc]initWithFrame:CGRectMake(150, 300, 150, 30)];
    self.passwordText.placeholder=@"Password";
    self.passwordText.borderStyle=UITextBorderStyleBezel;
    self.passwordText.delegate=self;
    self.passwordText.clearButtonMode=YES;
    self.passwordText.clearsOnBeginEditing=YES;
    self.passwordText.secureTextEntry=YES;
    [self.userView addSubview:self.passwordText];
    
    //repassword
    self.rePasswordLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 350, 100, 30)];
    self.rePasswordLabel.text=@"RePassword";
    self.rePasswordLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.rePasswordLabel];
    
    self.rePasswordText=[[UITextField alloc]initWithFrame:CGRectMake(150, 350, 150, 30)];
    self.rePasswordText.placeholder=@"RePassword";
    self.rePasswordText.borderStyle=UITextBorderStyleBezel;
    self.rePasswordText.delegate=self;
    self.rePasswordText.clearsOnBeginEditing=YES;
    self.rePasswordText.clearButtonMode=YES;
    self.rePasswordText.secureTextEntry=YES;
    [self.userView addSubview:self.rePasswordText];
    
    //address
    self.addressLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 400, 100, 30)];
    self.addressLabel.text=@"Address";
    self.addressLabel.textColor=[UIColor redColor];
    [self.userView addSubview:self.addressLabel];
    
    self.addressTable=[[UITextView alloc]initWithFrame:CGRectMake(150, 400, 150, 100)];
    // self.addressTable.text=@"fill address";
    self.addressTable.layer.borderWidth = 3.0f;
    self.addressTable.layer.borderColor = [[UIColor grayColor] CGColor];
    self.addressTable.clearsOnInsertion=YES;
    [self.userView addSubview:self.addressTable];
    
    //agree
    self.agreeSeg=[[UISegmentedControl alloc]initWithItems:@[@"Agree",@"DisAgree"]];
    self.agreeSeg.frame=CGRectMake(100, 520, 200, 30);
    [self.agreeSeg addTarget:self action:@selector(submition) forControlEvents:UIControlEventValueChanged];
    [self.userView addSubview:self.agreeSeg];
    
    //userName
    self.userNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 50, 100, 30)];
    self.userNameLabel.text=@"Email";
    // self.userNameLabel.textColor=[UIColor grayColor];
    [self.existView addSubview:self.userNameLabel];
    
    self.usernameText=[[UITextField alloc]initWithFrame:CGRectMake(150, 50, 150, 30)];
    self.usernameText.placeholder=@"Email";
    self.usernameText.borderStyle=UITextBorderStyleBezel;
    self.usernameText.layer.borderWidth=3;
    self.usernameText.layer.cornerRadius=5;
    self.usernameText.clearsOnBeginEditing=YES;
    self.usernameText.clearButtonMode=YES;
    self.usernameText.textAlignment=NSTextAlignmentRight;
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 25)];
    imageView1.image = [UIImage imageNamed:@"1.jpeg"];
    [self.usernameText addSubview:imageView1];
    
    [self.existView addSubview:self.usernameText];
    
    //password
    self.userPasswordLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 100, 100, 30)];
    self.userPasswordLabel.text=@"Password";
    self.userPasswordLabel.textColor=[UIColor blackColor];
    [self.existView addSubview:self.userPasswordLabel];
    
    self.userPasswordText=[[UITextField alloc]initWithFrame:CGRectMake(150, 100, 150, 30)];
    self.userPasswordText.placeholder=@"Password";
    self.userPasswordText.borderStyle=UITextBorderStyleBezel;
    self.userPasswordText.layer.borderWidth=3;
    self.userPasswordText.layer.cornerRadius=5;
    self.userPasswordText.clearButtonMode=YES;
    self.userPasswordText.clearsOnBeginEditing=YES;
    self.userPasswordText.secureTextEntry=YES;
    self.userPasswordText.textAlignment=NSTextAlignmentRight;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 25)];
    imageView.image = [UIImage imageNamed:@"2.jpeg"];
    [self.userPasswordText addSubview:imageView];
    [self.existView addSubview:self.userPasswordText];
    
    //login
    self.login=[UIButton buttonWithType:UIButtonTypeSystem];
    self.login.frame=CGRectMake(150, 150, 100, 30);
    [self.login setTitle:@"Login" forState:UIControlStateNormal];
    self.login.backgroundColor=[UIColor grayColor];
   // [self.login addTarget:self action:@selector(details) forControlEvents:UIControlEventTouchUpInside];
    [self.existView addSubview:self.login];
    
}
-(void)userDetails
{
    if(self.userSeg.selectedSegmentIndex==0)
    {
        self.userView.hidden=NO;
        self.existView.hidden=YES;
        self.loginView.hidden=YES;

    }
    else if(self.userSeg.selectedSegmentIndex==1)
    {
        self.existView.hidden=NO;
        self.userView.hidden=YES;
        self.loginView.hidden=YES;
    
    }
    
}
-(void)submition
{
    if (self.agreeSeg.selectedSegmentIndex==0) {
        self.submitButton.hidden=NO;
        //submit
        self.submitButton=[UIButton buttonWithType:UIButtonTypeSystem];
        self.submitButton.frame=CGRectMake(150, 570, 100, 30);
        self.submitButton.backgroundColor=[UIColor orangeColor];
        [self.submitButton setTitle:@"Submit" forState:UIControlStateNormal];
        [self.submitButton addTarget:self action:@selector(storing) forControlEvents:UIControlEventTouchUpInside];
        
        [self.userView addSubview:self.submitButton];

    } else if(self.agreeSeg.selectedSegmentIndex==1){
        self.submitButton.hidden=YES;
    }
    
}
-(void)storing
{
            self.addrry=[[NSMutableArray alloc]initWithObjects:self.firstText.text,self.lastText.text,self.genderSeg.selectedSegmentIndex,self.mobileText.text,self.emailText.text,self.passwordText.text,self.rePasswordText.text,self.cityText.text,self.addressTable.text, nil];
            [self.svng setObject:self.addrry forKey:self.emailText.text];

    if (self.firstText.text.length>0 && self.lastText.text.length>0 && self.mobileText.text.length>0 && self.cityText.text.length>0 && self.emailText.text.length>0 && self.passwordText.text.length>0 && self.rePasswordText.text.length>0)
        
    {
       
    if ([self.passwordText.text isEqualToString:self.rePasswordText.text]) {
     //   NSString * seg=[[NSString alloc]initWithString:[self.genderSeg titleForSegmentAtIndex:self.genderSeg.selectedSegmentIndex]];
        
//        self.addrry=[[NSMutableArray alloc]initWithObjects:self.firstText.text,self.lastText.text,self.genderSeg.selectedSegmentIndex,self.mobileText.text,self.emailText.text,self.passwordText.text,self.rePasswordText.text,self.cityText.text,self.addressTable.text, nil];
//        [self.svng setObject:self.addrry forKey:self.emailText.text];
       // for (id key in self.svng)
        {
            if ([self.passwordText.text isEqualToString:self.rePasswordText.text])
            {
                NSString *fN=[self.addrry objectAtIndex:0];
                NSString *lN=[self.addrry objectAtIndex:1];
                NSString *full=[fN stringByAppendingString:lN];
                self.firstLabel.text=full;
                self.genderLabel.text=[self.addrry objectAtIndex:2];
                self.mobileLabel.text=[self.addrry objectAtIndex:3];
                self.cityLabel.text=[self.addrry objectAtIndex:7];
                self.emailLabel.text=[self.addrry objectAtIndex:4];
                self.addressLabel.text=[self.addrry objectAtIndex:8];
                
            }
        }
        
//        NSMutableDictionary *person=[[NSMutableDictionary alloc]initWithObjects:@[self.firstText.text,self.lastText.text,seg,self.mobileText.text,self.cityText.text,self.emailText.text,self.passwordText.text,self.rePasswordText.text] forKeys:@[@"FN",@"LN",@"GEN",@"MOB",@"CTY",@"EML",@"PWD",@"REPWD"]];
//        [self.ary addObject:person];
//        NSLog(@"%@",person);
//        UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"message" message:@"submitted successfully" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction * action=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
//        [alert addAction:action];
//        [self presentViewController:alert animated:YES completion:nil];
//    }
//    else
//    {
//        UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Warning" message:@"Check Your password" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction * action=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
//        [alert addAction:action];
//        [self presentViewController:alert animated:YES completion:nil];
//    }
//
//    }
//    else{
//        UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Warning" message:@"fill all details" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction * action=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
//        [alert addAction:action];
//        [self presentViewController:alert animated:YES completion:nil];
//    }
//  
    
//}
//    }
//}

//-(void)details
//{
//    
//    for (int i=0; i<=self.ary.count-1; i++) {
//        NSMutableDictionary * obj = [self.ary objectAtIndex:i];
//        NSString *firstName=[obj objectForKey:@"FN"];
//        NSString *lastName=[obj objectForKey:@"LN"];
//        NSString *gender=[obj objectForKey:@"GEN"];
//        NSString *mobile=[obj objectForKey:@"MOB"];
//        NSString *city=[obj objectForKey:@"CTY"];
//        NSString *email=[obj objectForKey:@"EML"];
//        NSString *password=[obj objectForKey:@"PWD"];
//       // NSString *repassword=[obj objectForKey:@"REPWD"];
//        
//        self.userView.hidden=YES;
//        self.existView.hidden=YES;
//        self.loginView =[[UIScrollView alloc]initWithFrame:CGRectMake(10, 100, 350, 700)];
////        self.loginView.backgroundColor=[UIColor grayColor];
//        self.loginView.contentSize=CGSizeMake(1000, 1000);
//        [self.view addSubview:self.loginView];

       }
    else{
        UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"error" message:@"check email & password" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * action=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:action];
        
        
        [self presentViewController:alert animated:YES completion:nil];
    }
        
   
}
 }

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    if (textField==self.firstText) {
        NSCharacterSet * firstNameTextSet=[NSCharacterSet characterSetWithCharactersInString:@"qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM"];
        for (int i=0; i<[string length]; i++) {
            unichar c = [string characterAtIndex:i];
            if (![firstNameTextSet characterIsMember:c]) {
                return NO;
            }
        }
        NSUInteger firstNameLength=self.firstText.text.length-range.length;
        return (firstNameLength<20);
    }
    if (textField==self.lastText) {
        NSCharacterSet * lastNameTextSet=[NSCharacterSet characterSetWithCharactersInString:@"qwertyuioplkjhgfdsazxcvbnmPOIUYTREWQASDFGHJKLMNBVCXZ"];
        for (int i=0; i<[string length]; i++) {
            unichar c=[string characterAtIndex:i];
            if (![lastNameTextSet characterIsMember:c]) {
                return NO;
            }
        }
        NSUInteger lastNameLength=self.lastText.text.length-range.length;
        return (lastNameLength<20);
    }
    if (textField==self.mobileText) {
        NSCharacterSet *mobileTextSet=[NSCharacterSet characterSetWithCharactersInString:@"1234567890"];
        for (int i=0; i<[string length]; i++) {
            unichar c=[string characterAtIndex:i];
            if (![mobileTextSet characterIsMember:c]) {
                return NO;
            }
        }
        NSUInteger mobileTextLength=self.mobileText.text.length;
       // NSLog(@"%lu",(unsigned long)emailTextLength);
       // NSLog(@"%lu",(unsigned long)range.length);
        return (mobileTextLength<10);
    }
    if (textField==self.cityText) {
        NSCharacterSet *cityTextSet=[NSCharacterSet characterSetWithCharactersInString:@"qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM"];
        for (int i=0; i<[string length]; i++) {
            unichar c=[string characterAtIndex:i];
            if (![cityTextSet characterIsMember:c]) {
                return NO;
            }
        }
        NSUInteger cityTextLength=self.cityText.text.length;
        return (cityTextLength<15);
    }
    if (textField==self.passwordText) {
        NSCharacterSet * passwordTextSet=[NSCharacterSet characterSetWithCharactersInString:@"qwertyuioplkjhgfdsazxcvbnm,./';[]09-=87654321!@#$%^&*()_+}{:"];
        for (int i=0; i<[string length]; i++) {
            unichar c=[string characterAtIndex:i];
            if (![passwordTextSet characterIsMember:c]) {
                return NO;
            }
        }
        NSUInteger passwordTextLength=self.passwordText.text.length;
        return (passwordTextLength<15);
    }
    if (textField==self.rePasswordText) {
        NSCharacterSet * rePasswordTextSet=[NSCharacterSet characterSetWithCharactersInString:@"qwertyuioplkjhgfdsazxcvbnm,./';[]09-=87654321!@#$%^&*()_+}{:"];
        for (int i=0; i<[string length]; i++) {
            unichar c=[string characterAtIndex:i];
            if (![rePasswordTextSet characterIsMember:c]) {
                return NO;
            }
        }
        NSUInteger rePasswordTextLength=self.rePasswordText.text.length;
        return (rePasswordTextLength<15);
    }
    if (textField==self.emailText) {
        NSCharacterSet *emailTextSet=[NSCharacterSet characterSetWithCharactersInString:@"qwertyuiolpkjhgfdsazxcvbnmQAZWSXEDCRFVTGBYHNUJMIKOLP@."];
        for (int i=0; i<[string length]; i++) {
            unichar c=[string characterAtIndex:i];
            if (![emailTextSet characterIsMember:c]) {
                return NO;
            }
        }
        NSUInteger emailTextLength=self.emailText.text.length;
        return (emailTextLength<20);
    }
       
    return YES;
    
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    if (textField==self.firstText) {
        if (self.firstText.text.length>0) {
            return YES;
        } else {
            return NO;
        }
    }
    if (textField==self.lastText) {
        if (self.lastText.text.length>0) {
            return YES;
        } else {
            return NO;
        }
    }
    if (textField==self.mobileText) {
        if (self.mobileText.text.length>0) {
            return YES;
        } else {
            return NO;
        }
    }
    if (textField==self.cityText) {
        if (self.cityText.text.length>0) {
            return YES;
        } else {
            return NO;
        }
    }
    if (textField==self.emailText) {
        if (self.emailText.text.length>0) {
            return YES;
        } else {
            return NO;
        }
    }
    if (textField==self.passwordText) {
        if (self.passwordText.text.length>0) {
            return YES;
        } else {
            return NO;
        }
    }
    if (textField==self.rePasswordText) {
        if (self.rePasswordText.text.length>0) {
            return YES;
        } else {
            return NO;
        }
    }
    
    return YES;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Previous
Next Post »