VC.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextFieldDelegate>
- (IBAction)userSeg:(UISegmentedControl *)sender;
@property (weak, nonatomic) IBOutlet UISegmentedControl *userSegment;
@property (weak, nonatomic) IBOutlet UIScrollView *userView;
@property (weak, nonatomic) IBOutlet UITextField *firstNameTF;
@property (weak, nonatomic) IBOutlet UITextField *lastNameTF;
@property (weak, nonatomic) IBOutlet UISegmentedControl *genderSegment;
@property (weak, nonatomic) IBOutlet UITextField *mobileTF;
@property (weak, nonatomic) IBOutlet UITextField *cityTF;
@property (weak, nonatomic) IBOutlet UITextField *emailTF;
@property (weak, nonatomic) IBOutlet UITextField *passwordTF;
@property (weak, nonatomic) IBOutlet UITextField *reenterPasswordTF;
@property (weak, nonatomic) IBOutlet UISegmentedControl *agreeSegment;
- (IBAction)agreeSeg:(UISegmentedControl *)sender;
- (IBAction)signupButton:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIButton *signupBtn;
@property (weak, nonatomic) IBOutlet UIScrollView *existView;
@property (weak, nonatomic) IBOutlet UITextField *userNameTF;
@property (weak, nonatomic) IBOutlet UITextField *userPasswordTF;
- (IBAction)loginButton:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIScrollView *outputView;
@property (weak, nonatomic) IBOutlet UILabel *firstNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *lastNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *mobileLabel;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet UILabel *passwordLabel;
@property (weak, nonatomic) IBOutlet UILabel *firstNameOutput;
@property (weak, nonatomic) IBOutlet UILabel *lastNameOutput;
@property (weak, nonatomic) IBOutlet UILabel *mobileOutput;
@property (weak, nonatomic) IBOutlet UILabel *genderOutput;
@property (weak, nonatomic) IBOutlet UILabel *genderLabel;
@property (weak, nonatomic) IBOutlet UILabel *cityOutput;
@property (weak, nonatomic) IBOutlet UILabel *emailOutput;
@property (weak, nonatomic) IBOutlet UILabel *passwordOutput;
@property NSMutableArray *ary;
@property NSMutableDictionary *dic,*savingD;
@end
VC.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.dic=[[NSMutableDictionary alloc]init];
self.ary=[[NSMutableArray alloc]init];
self.savingD=[[NSMutableDictionary alloc]init];
self.firstNameTF.delegate=self;
self.lastNameTF.delegate=self;
self.mobileTF.delegate=self;
self.cityTF.delegate=self;
self.emailTF.delegate=self;
self.passwordTF.delegate=self;
self.reenterPasswordTF.delegate=self;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)agreeSeg:(UISegmentedControl *)sender {
if (self.agreeSegment.selectedSegmentIndex==0) {
self.signupBtn.hidden=NO;
}
else if (self.agreeSegment.selectedSegmentIndex==1) {
self.signupBtn.hidden=YES;
}
}
- (IBAction)signupButton:(UIButton *)sender {
NSString *gen=[[NSString alloc]initWithString:[self.genderSegment titleForSegmentAtIndex:self.genderSegment.selectedSegmentIndex]];
self.dic=[[NSMutableDictionary alloc]initWithObjects:@[self.firstNameTF.text,self.lastNameTF.text,gen,self.mobileTF.text,self.cityTF.text,self.emailTF.text,self.passwordTF.text,self.reenterPasswordTF.text] forKeys:@[@"FN",@"LN",@"GN",@"MN",@"CN",@"EN",@"PN",@"RN"]];
[self.ary addObject:self.dic];
if (self.firstNameTF.text.length>0 && self.lastNameTF.text.length>0 && self.mobileTF.text.length>0 && self.cityTF.text.length>0 && self.emailTF.text.length>0 && self.passwordTF.text.length>0 && self.reenterPasswordTF.text.length>0) {
if ([self.passwordTF.text isEqualToString:self.reenterPasswordTF.text]) {
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Submit" message:@"Data 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:@"error" message:@"give correct 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:@"Error" 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];
}
[self remove];
}
- (IBAction)userSeg:(UISegmentedControl *)sender {
if (self.userSegment.selectedSegmentIndex==0) {
self.userView.hidden=NO;
self.existView.hidden=YES;
self.outputView.hidden=YES;
}
else if (self.userSegment.selectedSegmentIndex==1) {
self.userView.hidden=YES;
self.existView.hidden=NO;
self.outputView.hidden=YES;
}
}
-(void)remove
{
self.firstNameTF.text=0;
self.lastNameTF.text=0;
self.mobileTF.text=0;
self.cityTF.text=0;
self.emailTF.text=0;
self.passwordTF.text=0;
self.reenterPasswordTF.text=0;
}
- (IBAction)loginButton:(UIButton *)sender {
for (int i=0; i<=self.ary.count-1; i++) {
NSMutableDictionary *person=[self.ary objectAtIndex:i];
NSString *firstName=[person objectForKey:@"FN"];
NSString *lastName=[person objectForKey:@"LN"];
NSString *gender=[person objectForKey:@"GN"];
NSString *mobile=[person objectForKey:@"MN"];
NSString *city=[person objectForKey:@"CN"];
NSString *email=[person objectForKey:@"EN"];
NSString *password=[person objectForKey:@"PN"];
// NSString *repassword=[person objectForKey:@"RN"];
self.userView.hidden=YES;
self.existView.hidden=YES;
self.outputView.hidden=NO;
if ([self.userNameTF.text isEqualToString:email] && [self.userPasswordTF.text isEqualToString:password]) {
[self.firstNameOutput setText:firstName];
[self.lastNameOutput setText:lastName];
[self.genderOutput setText:gender];
[self.mobileOutput setText:mobile];
[self.cityOutput setText:city];
[self.emailOutput setText:email];
[self.passwordOutput setText:password];
}
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.firstNameTF || textField==self.lastNameTF || textField==self.cityTF) {
NSCharacterSet *firstNameSet=[NSCharacterSet characterSetWithCharactersInString:@"zxcvbnmlkjhgfdsaqwertyuiopPOIUYTREWQASDFGHJKLMNBVCXZ"];
for (int i=0; i<[string length];i++) {
unichar c=[string characterAtIndex:i];
if (![firstNameSet characterIsMember:c]) {
return NO;
}
}
NSUInteger firstLength=self.firstNameTF.text.length-range.length;
NSUInteger lastLength=self.lastNameTF.text.length-range.length;
NSUInteger cityLength=self.cityTF.text.length-range.length;
return (firstLength<20);
return (lastLength<20);
return (cityLength<20);
}
if (textField==self.mobileTF) {
NSCharacterSet *mobileSet=[NSCharacterSet characterSetWithCharactersInString:@"1236547890"];
for (int i=0; i<[string length]; i++) {
unichar c=[string characterAtIndex:i];
if (![mobileSet characterIsMember:c]) {
return NO;
}
}
NSUInteger mobileLength=self.mobileTF.text.length-range.length;
return (mobileLength<10);
}
if (textField==self.emailTF || textField==self.passwordTF || textField==self.reenterPasswordTF) {
NSCharacterSet *emailSet=[NSCharacterSet characterSetWithCharactersInString:@"0123654789*+-.@!#$%^&*()_qwertyuoplkasdfghjzxcvbnm,QWERTYUIOPASDFGHJKLZXCVBNM"];
for (int i=0; i<[string length]; i++) {
unichar c=[string characterAtIndex:i];
if (![emailSet characterIsMember:c]) {
return NO;
}
}
NSUInteger emailLength=self.emailTF.text.length-range.length;
NSUInteger passwordLength=self.passwordTF.text.length-range.length;
NSUInteger reenterPasswordLength=self.reenterPasswordTF.text.length-range.length;
return (emailLength<20);
return (passwordLength<20);
return (reenterPasswordLength<20);
}
return YES;
}
@end
Sign up here with your email
ConversionConversion EmoticonEmoticon