Skip to content

Instantly share code, notes, and snippets.

@hemant3370
Created November 30, 2015 10:19
Show Gist options
  • Save hemant3370/c33e22f0d6af3107080b to your computer and use it in GitHub Desktop.
Save hemant3370/c33e22f0d6af3107080b to your computer and use it in GitHub Desktop.
viewdidload with picker delegates
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[[self navigationController] setNavigationBarHidden:NO animated:NO];
pickerArray = [[NSArray alloc]init];
txtContent = [[NSString alloc]init];
__autoreleasing NSError* error = nil;
NSStringEncoding* enc = nil;
NSString *fileDirectory = [[NSBundle mainBundle] resourcePath];
NSString *path = [NSString stringWithFormat:@"%@/countryList.txt",fileDirectory];
txtContent = [NSString stringWithContentsOfFile:path usedEncoding:enc error:&error];
if (txtContent != nil) {
NSLog(@"%@",txtContent);
}
pickerArray =[txtContent componentsSeparatedByString:@","];
if (pickerArray != nil) {
NSLog(@"%lu",(unsigned long)pickerArray.count);
}
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component{
[txtCountry setText:[pickerArray objectAtIndex:row]];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:
(NSInteger)row forComponent:(NSInteger)component{
return [pickerArray objectAtIndex:row];
}
#pragma mark - Picker View Data source
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
return [pickerArray count];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment