Created
September 2, 2016 10:04
-
-
Save goel232/0bfecbbcd09e28c0b674873a984cbb52 to your computer and use it in GitHub Desktop.
Want to populate data from two array one at a time using same TableView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RegisterScreen.m | |
// vehicleApp | |
// | |
// Created by Aethon Technologies on 25/08/16. | |
// Copyright © 2016 Aethon Technologies. All rights reserved. | |
// | |
#import "RegisterScreen.h" | |
@interface RegisterScreen (){ | |
NSMutableArray *countryArray; | |
NSMutableArray *stateArray; | |
NSMutableArray *cityArray; | |
NSMutableArray *tempArray; | |
BOOL isCountry; | |
BOOL isState; | |
NSInteger count; | |
} | |
@end | |
@implementation RegisterScreen | |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ | |
NSLog(@"touchesBegan:withEvent:"); | |
[self.view endEditing:YES]; | |
[super touchesBegan:touches withEvent:event]; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view from its nib. | |
self.navigationItem.title=@"Registration"; | |
//rounding the frame ! | |
self.profilePic.layer.cornerRadius = self.profilePic.frame.size.width / 2; | |
//self.profilePic.layer.borderWidth = 3.0f; | |
// self.profilePic.layer.borderColor = [UIColor whiteColor].CGColor; | |
self.profilePic.clipsToBounds = YES; | |
//setting up image in button | |
UIImage *buttonImage = [UIImage imageNamed:@"apple.png"]; | |
[_selectimage setBackgroundImage:buttonImage forState:UIControlStateNormal]; | |
_registerUserName.borderStyle=UITextBorderStyleRoundedRect; | |
_regiterUserLastName.borderStyle=UITextBorderStyleRoundedRect; | |
_registerEmail.borderStyle=UITextBorderStyleRoundedRect; | |
_registerMobile.borderStyle=UITextBorderStyleRoundedRect; | |
_registerDOB.borderStyle=UITextBorderStyleRoundedRect; | |
_registerAddress.borderStyle=UITextBorderStyleRoundedRect; | |
_registerCountry.borderStyle=UITextBorderStyleRoundedRect; | |
_registerState.borderStyle=UITextBorderStyleRoundedRect; | |
_registerCity.borderStyle=UITextBorderStyleRoundedRect; | |
_registerArea.borderStyle=UITextBorderStyleRoundedRect; | |
_registerPinCode.borderStyle=UITextBorderStyleRoundedRect; | |
// [_dropDownCity setEnabled:NO]; | |
// [_dropDownState setEnabled:NO]; | |
UIDatePicker *datePicker=[[UIDatePicker alloc]init]; | |
[datePicker setDate:[NSDate date]]; | |
datePicker.datePickerMode = UIDatePickerModeDate; | |
[datePicker addTarget:self action:@selector(dateTextField:) forControlEvents:UIControlEventValueChanged]; | |
[self.registerDOB setInputView:datePicker]; | |
NSString *path=[[NSBundle mainBundle] pathForResource:@"countries" ofType:@"plist"]; | |
NSDictionary *dic=[[NSDictionary alloc]initWithContentsOfFile:path]; | |
countryArray =[dic objectForKey:@"countries"]; | |
/* | |
countryArray = [[NSMutableArray alloc] initWithObjects:@"Afghanistan",@"Åland Islands",@"Albania",@"Algeria",@"India",@"American Samoa", nil]; | |
*/ | |
stateArray = [[NSMutableArray alloc]initWithObjects:@"Gujarat",@"Maharashtra", @"Karnataka",nil]; | |
} | |
-(void) dateTextField:(id)sender{ | |
UIDatePicker *picker = (UIDatePicker*)self.registerDOB.inputView; | |
[picker setMaximumDate:[NSDate date]]; | |
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; | |
NSDate *eventDate = picker.date; | |
[dateFormat setDateFormat:@"dd/MM/yyyy"]; | |
NSString *dateString = [dateFormat stringFromDate:eventDate]; | |
self.registerDOB.text = [NSString stringWithFormat:@"%@",dateString]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
/* | |
#pragma mark - Navigation | |
// In a storyboard-based application, you will often want to do a little preparation before navigation | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
// Get the new view controller using [segue destinationViewController]. | |
// Pass the selected object to the new view controller. | |
} | |
*/ | |
- (IBAction)imagePicker:(id)sender { | |
/* UIImagePickerController *picker = [[UIImagePickerController alloc] init]; | |
picker.sourceType = UIImagePickerControllerSourceTypeCamera; | |
picker.delegate = self; | |
picker.allowsEditing = YES; | |
[self presentViewController:picker animated:YES completion:NULL]; | |
*/ | |
// allocated image picker controller by the name picker | |
UIImagePickerController *picker = [[UIImagePickerController alloc] init]; | |
// If our device has a camera, we want to take a picture, otherwise, we just pick from | |
// photo library | |
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) | |
{ | |
[picker setSourceType:UIImagePickerControllerSourceTypeCamera]; | |
// image picker needs a delegate so we can respond to its messages | |
picker.delegate = self; | |
picker.allowsEditing = YES; | |
[self presentViewController:picker animated:YES completion:nil]; | |
// [self presentModalViewController:picker animated:YES]; | |
}else | |
{ | |
// [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; | |
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Device has no camera" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; | |
[myAlertView show]; | |
} | |
} | |
- (IBAction)selectPicker:(id)sender { | |
UIImagePickerController *picker = [[UIImagePickerController alloc] init]; | |
picker.delegate = self; | |
picker.allowsEditing = YES; | |
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; | |
[self presentViewController:picker animated:YES completion:NULL]; | |
} | |
#pragma mark - Image Picker Controller delegate methods | |
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { | |
UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; | |
self.profilePic.image = chosenImage; | |
[picker dismissViewControllerAnimated:YES completion:NULL]; | |
} | |
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { | |
// [picker dismissViewControllerAnimated:YES completion:NULL]; | |
[[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil]; | |
} | |
#pragma Country Drop Down | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return count; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
return 25; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
UITableViewCell *cell; | |
if(isCountry){ | |
// tempArray=countryArray; | |
static NSString *idenfier = @"countryList"; | |
cell = [tableView dequeueReusableCellWithIdentifier:idenfier forIndexPath:indexPath]; | |
cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
cell.textLabel.text = [countryArray objectAtIndex:indexPath.row]; | |
[_countryView reloadData]; | |
}else if (isState) { | |
static NSString *idenfier = @"countryList"; | |
cell = [tableView dequeueReusableCellWithIdentifier:idenfier forIndexPath:indexPath]; | |
cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
cell.textLabel.text = [stateArray objectAtIndex:indexPath.row]; | |
[_countryView reloadData]; | |
}; | |
return cell; | |
} | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
if(isCountry){ | |
self.registerCountry.text = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text]; | |
// self.countryView.hidden = YES; | |
self.countryView.frame = CGRectMake(self.countryView.frame.origin.x, self.countryView.frame.origin.y, self.countryView.frame.size.width, 0); | |
}else if (isState) | |
{ | |
self.registerState.text = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text]; | |
// self.countryView.hidden = YES; | |
self.countryView.frame = CGRectMake(self.countryView.frame.origin.x, self.countryView.frame.origin.y, self.countryView.frame.size.width, 0); | |
} | |
} | |
- (IBAction)dropDownCountry:(id)sender { | |
isCountry =YES; | |
isState=NO; | |
count=countryArray.count; | |
NSLog(@"%ld",(long)count); | |
self.countryView.hidden = NO; | |
if (self.countryView.frame.size.height != 0) { | |
[UIView animateWithDuration:0.3 animations:^{ | |
self.countryView.frame = CGRectMake(self.countryView.frame.origin.x, self.countryView.frame.origin.y, self.countryView.frame.size.width, 0); | |
} completion:^(BOOL finished) { | |
// self.dropDownImageView.highlighted = NO; | |
}]; | |
} | |
else { | |
[UIView animateWithDuration:0.3 animations:^{ | |
self.countryView.frame = CGRectMake(10, 404, 302, 100); | |
} completion:^(BOOL finished) { | |
// self.dropDownImageView.highlighted = YES; | |
}]; | |
} | |
} | |
#pragma State Drop Down | |
- (IBAction)dropDownState:(id)sender { | |
isState =YES; | |
isCountry=NO; | |
count=stateArray.count; | |
NSLog(@"%ld",(long)count); | |
self.countryView.hidden = NO; | |
if (self.countryView.frame.size.height != 0) { | |
[UIView animateWithDuration:0.3 animations:^{ | |
self.countryView.frame = CGRectMake(self.countryView.frame.origin.x, self.countryView.frame.origin.y, self.countryView.frame.size.width, 0); | |
} completion:^(BOOL finished) { | |
// self.dropDownImageView.highlighted = NO; | |
}]; | |
} | |
else { | |
[UIView animateWithDuration:0.3 animations:^{ | |
self.countryView.frame = CGRectMake(10, 404, 302, 100); | |
} completion:^(BOOL finished) { | |
// self.dropDownImageView.highlighted = YES; | |
}]; | |
} | |
} | |
#pragma City Drop Down | |
- (IBAction)dropDownCity:(id)sender { | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment