Alert Controller

Alert Controller 




VC.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property UIScrollView * userView,*loginView,*details;

@property UISegmentedControl *segmentNames,* genderSegment,*stateSegment,*agreeSegment;

@property UILabel * firstName,*lastName,*gender,*mobile,*city,*state,*eMail,*password,*reTypePassword;

@property UITextField *firstNameTF,*lastNameTF,*mobileTF,*cityTF,*eMailTF,*passwordTF,*reTypePasswordTF;


@property UILabel * eMail1,*password1,*alertLB;
@property UITextField * eMailTF1,*passwordTF1;

@property UIButton * submit,*login,*home;

@property NSMutableArray *array;
@property NSMutableDictionary * dict;



@property UILabel * FNLB,* LNLB, * mobileLB, * genderLB,* cityLB, * stateLB, * eMailLB,* passwordLB;

@property UILabel *FN, *LN,*selectGender, *mobileN, *cityN, *stateN, *emailLogin, *pwdLogin;


@end


VC.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createElements];
    // Do any additional setup after loading the view, typically from a nib.
}
-(void)createElements
{
    self.array=[[NSMutableArray alloc]init];
    self.segmentNames=[[UISegmentedControl alloc]initWithItems:@[@"New User",@"Existing User"]];
   self.segmentNames.frame=CGRectMake(70, 30, 200, 30);
   self.segmentNames.momentary=YES;
    [self.segmentNames addTarget:self action:@selector(newUser:)
forControlEvents:UIControlEventValueChanged];
    [self.segmentNames setSelectedSegmentIndex:1];
   [self.view addSubview:self.segmentNames];
    [self newUser:self.loginView];
}
-(void)newUser:(id)sender
{
    if (self.segmentNames.selectedSegmentIndex==0) {
        
        self.loginView.hidden=YES;
        self.details.hidden=YES;
        
    self.userView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 70, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
    [self.userView setBackgroundColor:[UIColor lightGrayColor]];
    self.userView.contentSize=CGSizeMake(200, 800);
    [self.view addSubview:self.userView];

    self.firstName=[[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 30)];
    self.firstName.text=@"FirstName ";
    self.firstName.textColor=[UIColor redColor];
    [self.userView addSubview:self.firstName];
    
    self.lastName=[[UILabel alloc]initWithFrame:CGRectMake(10, 70, 100, 30)];
    self.lastName.text=@"LastName ";
    self.lastName.textColor=[UIColor redColor];
    [self.userView addSubview:self.lastName];
    
        self.gender=[[UILabel alloc]initWithFrame:CGRectMake(10, 120, 100, 30)];
        self.gender.text=@"Gender ";
        self.gender.textColor=[UIColor redColor];
        [self.userView addSubview:self.gender];
        
        self.mobile=[[UILabel alloc]initWithFrame:CGRectMake(10, 170, 100, 40)];
        [self.mobile setText:@"Mobile"];
     self.mobile.textColor=[UIColor redColor];
        [self.userView addSubview:self.mobile];
        
        self.city=[[UILabel alloc]initWithFrame:CGRectMake(10, 220, 100, 40)];
        [self.city setText:@"city"];
     self.city.textColor=[UIColor redColor];
        [self.userView addSubview:self.city];
        
        
        self.state=[[UILabel alloc]initWithFrame:CGRectMake(10, 270, 150, 40)];
        [self.state setText:@"state"];
     self.state.textColor=[UIColor redColor];
        [self.userView addSubview:self.state];
        
        self.eMail=[[UILabel alloc]initWithFrame:CGRectMake(10, 320, 100, 40)];
        [self.eMail setText:@"eMail"];
         self.eMail.textColor=[UIColor redColor];
        [self.userView addSubview:self.eMail];
        
        self.password=[[UILabel alloc]initWithFrame:CGRectMake(10, 370, 100, 40)];
        [self.password setText:@"password"];
        self.password.textColor=[UIColor redColor];
        [self.userView addSubview:self.password];
        
        self.reTypePassword=[[UILabel alloc]initWithFrame:CGRectMake(10, 420, 100, 40)];
        [self.reTypePassword setText:@"rePassword"];
        self.reTypePassword.textColor=[UIColor redColor];
        [self.userView addSubview:self.reTypePassword];
        

    self.firstNameTF=[[UITextField alloc]initWithFrame:CGRectMake(120, 20, 250, 30)];
    self.firstNameTF.backgroundColor=[UIColor clearColor];
    self.firstNameTF.placeholder=@"FirstName";
    self.firstNameTF.layer.borderWidth=2;
    self.firstNameTF.clearButtonMode=YES;
    self.firstNameTF.borderStyle=UITextBorderStyleBezel;
    self.firstNameTF.keyboardType=UIKeyboardTypeDefault;
    [self.userView addSubview:self.firstNameTF];
        
    self.lastNameTF=[[UITextField alloc]initWithFrame:CGRectMake(120, 70, 250, 30)];
    self.lastNameTF.backgroundColor=[UIColor clearColor];
    self.lastNameTF.placeholder=@"LastName";
    self.lastNameTF.clearButtonMode=YES;
    self.lastNameTF.layer.borderWidth=2;
    self.lastNameTF.borderStyle=UITextBorderStyleBezel;
    self.lastNameTF.keyboardType=UIKeyboardTypeDefault;
    [self.userView addSubview:self.lastNameTF];
    
        self.genderSegment=[[UISegmentedControl alloc]initWithItems:@[@" MALE",@"FEMALE"]];
        self.genderSegment.frame = CGRectMake(120, 120, 250, 30);
        self.genderSegment.apportionsSegmentWidthsByContent=YES;
        [self.userView addSubview:self.genderSegment];
        
        
        self.mobileTF=[[UITextField alloc]initWithFrame:CGRectMake(120, 170, 250, 30)];
        self.mobileTF.backgroundColor=[UIColor clearColor];
        self.mobileTF.placeholder=@"enter mobile no";
        self.mobileTF.clearButtonMode=YES;
        self.mobileTF.layer.borderWidth=2;
        //self.mobileTF.delegate=self;
        self.mobileTF.borderStyle=UITextBorderStyleBezel;
        self.mobileTF.keyboardType=UIKeyboardTypeNumberPad;
        [self.userView addSubview:self.mobileTF];
        
        self.cityTF=[[UITextField alloc]initWithFrame:CGRectMake(120, 220, 250, 30)];
        self.cityTF.backgroundColor=[UIColor clearColor];
        self.cityTF.placeholder=@"city/town";
        self.cityTF.clearButtonMode=YES;
        self.cityTF.layer.borderWidth=2;
        //self.cityName.delegate=self;
        self.cityTF.borderStyle=UITextBorderStyleBezel;
        self.cityTF.keyboardType=UIKeyboardTypeDefault;
        [self.userView addSubview:self.cityTF];
        
        self.stateSegment=[[UISegmentedControl alloc]initWithItems:@[@"SI",@"EI",@"NI",@"WI"]];
        self.stateSegment.frame = CGRectMake(120, 270, 250, 30);
        self.stateSegment.apportionsSegmentWidthsByContent=YES;
        [self.userView addSubview:self.stateSegment];
        
        self.eMailTF=[[UITextField alloc]initWithFrame:CGRectMake(120, 320, 250, 30)];
        self.eMailTF.backgroundColor=[UIColor clearColor];
        self.eMailTF.placeholder=@"mani123@gmail.com";
        self.eMailTF.clearButtonMode=YES;
        self.eMailTF.layer.borderWidth=2;
       // self.eMailTF.delegate=self;
        self.eMailTF.borderStyle=UITextBorderStyleBezel;
        self.eMailTF.keyboardType=UIKeyboardTypeEmailAddress;
        [self.userView addSubview:self.eMailTF];
        
        self.passwordTF=[[UITextField alloc]initWithFrame:CGRectMake(120, 370, 250, 30)];
        self.passwordTF.backgroundColor=[UIColor clearColor];
        self.passwordTF.placeholder=@"passwordText";
       // self.passwordTF.delegate=self;
        self.passwordTF.clearButtonMode=YES;
        self.passwordTF.layer.borderWidth=2;
        self.passwordTF.borderStyle=UITextBorderStyleBezel;
        self.passwordTF.secureTextEntry=YES;
        self.passwordTF.keyboardType=UIKeyboardTypeDefault;
        [self.userView addSubview:self.passwordTF];
        
        self.reTypePasswordTF=[[UITextField alloc]initWithFrame:CGRectMake(120, 420, 250, 30)];
        self.reTypePasswordTF.backgroundColor=[UIColor clearColor];
        self.reTypePasswordTF.placeholder=@"reTypePassword";
        self.reTypePasswordTF.secureTextEntry=YES;
        self.reTypePasswordTF.layer.borderWidth=2;
        //self.reTypePasswordTF.delegate=self;
        self.reTypePasswordTF.clearButtonMode=YES;
        self.reTypePasswordTF.borderStyle=UITextBorderStyleBezel;
        self.reTypePasswordTF.keyboardType=UIKeyboardTypeDefault;
        [self.userView addSubview:self.reTypePasswordTF];
        
        self.agreeSegment=[[UISegmentedControl alloc]initWithItems:@[@"AGREE",@"DISAGREE"]];
        self.agreeSegment.frame = CGRectMake(30, 480, 200, 30);
        self.agreeSegment.apportionsSegmentWidthsByContent=YES;
        [self.agreeSegment addTarget:self action:@selector(agreeAction:) forControlEvents:UIControlEventValueChanged];

        [self.userView addSubview:self.agreeSegment];
        
        self.submit= [UIButton buttonWithType:UIButtonTypeSystem];
        self.submit.frame = CGRectMake(200, 520, 60, 30);
        self.submit.backgroundColor=[UIColor redColor];
        [self.submit setTitle:@"submit" forState:UIControlStateNormal];
        [self.submit addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];

       }
    else if (self.segmentNames.selectedSegmentIndex==1)
    {
        self.userView.hidden=YES;
        self.details.hidden=YES;
        self.loginView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 70, 372, 595)];
        self.loginView.backgroundColor=[UIColor grayColor];
        [self.view addSubview:self.loginView];
        
        
        
        self.eMail1=[[UILabel alloc]initWithFrame:CGRectMake(20, 50, 100, 40)];
        [self.eMail1 setText:@"eMail"];
        self.eMail1.textColor=[UIColor redColor];
        [self.loginView addSubview:self.eMail1];
        
        self.password=[[UILabel alloc]initWithFrame:CGRectMake(20, 100, 100, 40)];
        [self.password setText:@"password"];
        self.password.textColor=[UIColor redColor];
        [self.loginView addSubview:self.password];
        
        self.eMailTF1=[[UITextField alloc]initWithFrame:CGRectMake(120, 50, 250, 30)];
        self.eMailTF1.backgroundColor=[UIColor clearColor];
        self.eMailTF1.placeholder=@"username";
        // self.eMailTF2.delegate=self;
        self.eMailTF1.clearButtonMode=YES;
        self.eMailTF1.layer.borderWidth=2;
        self.eMailTF1.borderStyle=UITextBorderStyleBezel;
        [self.loginView addSubview:self.eMailTF1];

        
        self.passwordTF1=[[UITextField alloc]initWithFrame:CGRectMake(120, 100, 250, 30)];
        self.passwordTF1.backgroundColor=[UIColor clearColor];
        self.passwordTF1.placeholder=@"password";
       // self.passwordTF2.delegate=self;
        self.passwordTF1.clearButtonMode=YES;
        self.passwordTF1.layer.borderWidth=2;
        self.passwordTF1.secureTextEntry=YES;
        self.passwordTF1.borderStyle=UITextBorderStyleBezel;
        [self.loginView addSubview:self.passwordTF1];
        
        self.login= [UIButton buttonWithType:UIButtonTypeSystem];
        self.login.frame =CGRectMake(150, 160, 90, 40);
        self.login.backgroundColor=[UIColor redColor];
        [self.login setTitle:@"login" forState:UIControlStateNormal];
       [self.login addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
        [self.loginView addSubview:self.login];
   
    }
}
-(void)agreeAction:(id)sender

{
    if (self.agreeSegment.selectedSegmentIndex==0) {
        
        self.submit.hidden=NO;
        [self.userView addSubview:self.submit];
        
    }
    else if(self.agreeSegment.selectedSegmentIndex==1){
        UIAlertView * submitAlert =[[UIAlertView alloc]initWithTitle:@"alert" message:@"press agree" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [submitAlert show];
        
    }
}
-(void)submitAction:(id)sender{
    
    
    if ([self.firstNameTF.text isEqualToString:@""] || [self.lastNameTF.text isEqualToString:@""] || [self.mobileTF.text isEqualToString:@""] || [self.cityTF.text isEqualToString:@""] || [self.eMailTF.text isEqualToString:@""]|| [self.passwordTF.text isEqualToString:@""] ||  [self.reTypePasswordTF.text isEqualToString:@""]||self.genderSegment.selectedSegmentIndex==-1 ||self.stateSegment.selectedSegmentIndex==-1)
        
    {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Check All Details" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        
        [alertView show];
        NSLog(@"all are not filled");
        
    }
    else if (self.passwordTF.text == self.reTypePasswordTF.text)
    {
        self.loginView.hidden=YES;
        self.userView.hidden=YES;
        UIAlertView * successAlert =[[UIAlertView alloc]initWithTitle:@"alert" message:@"success" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [successAlert show];
        
          }
    else {
        
        UIAlertView * PWDAlert =[[UIAlertView alloc]initWithTitle:@"alert" message:@"check Password" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [PWDAlert show];
        
    }
    
    
    
}
-(void)loginAction
{
    if (self.array.count>0) {
        for (int i=0; i<=self.array.count-1; i++)
        {
            NSMutableDictionary *data=[self.array objectAtIndex:i];
            NSString *firstName=[data objectForKey:@"First"];
            NSString *lastName=[data objectForKey:@"Last"];
            NSString *mobile=[data objectForKey:@"MOB"];
            NSString *gender=[data objectForKey:@"GEN"];
            NSString * city =[data objectForKey:@"CITY"];
            NSString *state=[data objectForKey:@"ST"];
            NSString *eMail=[data objectForKey:@"EM"];
            NSString *password=[data objectForKey:@"PWD"];
            
            
            if( [self.eMailTF1.text isEqualToString:eMail] && [self.passwordTF1.text isEqualToString:password])
                
            {
                self.loginView.hidden=YES;
                self.userView.hidden=YES;
                
                
                self.details=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 80, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
                [self.details setBackgroundColor:[UIColor lightGrayColor]];
                
                [self.view addSubview:self.details];
                
                
                
                self.FNLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 80, 100, 30)];
                [self.FNLB setText:@"firstName"];
                [self.details addSubview:self.FNLB];
                
                
                
                
                self.LNLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 130, 100, 40)];
                [self.LNLB setText:@"lastName"];
                [self.details addSubview:self.LNLB];
                
                self.genderLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 180, 150, 40)];
                [self.genderLB setText:@"gender"];
                [self.details addSubview:self.genderLB];
                
                self.mobileLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 220, 100, 40)];
                [self.mobileLB setText:@"Mobile"];
                [self.details addSubview:self.mobileLB];
                
                self.cityLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 270, 100, 40)];
                [self.cityLB setText:@"city"];
                [self.details addSubview:self.cityLB];
                
                
                self.stateLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 320, 150, 40)];
                [self.stateLB setText:@"state"];
                [self.details addSubview:self.stateLB];
                
                self.eMailLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 370, 100, 40)];
                
                [self.eMailLB setText:@"eMail"];
                [self.details addSubview:self.eMailLB];
                
                self.passwordLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 420, 100, 40)];
                [self.passwordLB setText:@"password"];
                [self.details addSubview:self.passwordLB];
                
                
                
                self.FN=[[UILabel alloc]initWithFrame:CGRectMake(150, 80, 150, 30)];
                [self.FN setText:firstName];
                [self.details addSubview:self.FN];
                
                
                
                
                self.LN=[[UILabel alloc]initWithFrame:CGRectMake(150, 130, 150, 40)];
                [self.LN setText:lastName];
                [self.details addSubview:self.LN];
                
                self.selectGender=[[UILabel alloc]initWithFrame:CGRectMake(150, 180, 150, 40)];
                [self.selectGender setText:gender];
                [self.details addSubview:self.selectGender];
                
                self.mobileN=[[UILabel alloc]initWithFrame:CGRectMake(150, 220, 150, 40)];
                [self.mobileN setText:mobile];
                [self.details addSubview:self.mobileN];
                
                self.cityN=[[UILabel alloc]initWithFrame:CGRectMake(150, 270, 150, 40)];
                [self.cityN setText:city];
                [self.details addSubview:self.cityN];
                
                
                self.stateN=[[UILabel alloc]initWithFrame:CGRectMake(150, 320, 150, 40)];
                [self.stateN setText:state];
                [self.details addSubview:self.stateN];
                
                self.emailLogin=[[UILabel alloc]initWithFrame:CGRectMake(150, 370, 150, 40)];
                [self.emailLogin setText:eMail];
                [self.details addSubview:self.emailLogin];
                
                self.pwdLogin=[[UILabel alloc]initWithFrame:CGRectMake(150, 420, 150, 40)];
                [self.pwdLogin setText:password];
                [self.details addSubview:self.pwdLogin];
                
                               
                self.home=[UIButton buttonWithType:UIButtonTypeSystem];
                self.home.frame=CGRectMake(250, 470, 150, 40);
                [self.home setTitle:@"HOME" forState:UIControlStateNormal];
                [self.home addTarget:self action:@selector(newUser:) forControlEvents:UIControlEventTouchUpInside];
                [self.details addSubview:self.home];
                
            }
            
        }
        
    }
    if( [self.eMailTF1.text isEqualToString:@""] || [self.passwordTF1.text isEqualToString:@""]  )
    {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Check All Details" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        
        [alertView show];
    }
    else
    {   self.alertLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 250, 200, 40)];
        [self.alertLB setText:@"CHECK DETAILS AGAIN "];
        [self.loginView addSubview:self.alertLB];
    }
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Previous
Next Post »