I know this question has been asked before. but i having difficulty among those. as i have created picker by using this code.
@interface datePicker ()<UIPickerViewDataSource,UIPickerViewDelegate>
{
IBOutlet UIPickerView *picker;
IBOutlet UITextField *tfTime;
NSMutableArray *arrayData,*minData;
}
@end
@implementation datePicker
- (void)viewDidLoad {
[super viewDidLoad];
arrayData =[[NSMutableArray alloc]init];
minData=[[NSMutableArray alloc] init];
[arrayData addObject:@1];
[arrayData addObject:@2];
[arrayData addObject:@3];
[arrayData addObject:@4];
[arrayData addObject:@5];
[arrayData addObject:@6];
[arrayData addObject:@7];
[arrayData addObject:@8];
[arrayData addObject:@9];
[minData addObject:@01];
[minData addObject:@02];
[minData addObject:@03];
[minData addObject:@04];
[minData addObject:@05];
[minData addObject:@06];
[minData addObject:@07];
[minData addObject:@80];
[minData addObject:@90];
[minData addObject:@10];
[picker setDataSource:self];
[picker setDelegate:self];
[self.view addSubview:picker];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(component==0)
{
return [arrayData count];
}
else
{
return [minData count];
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(component==0)
return[NSString stringWithFormat:@"%@", [arrayData objectAtIndex:row]];
else
return [NSString stringWithFormat:@"%@",[minData objectAtIndex:row]];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
tfTime.text=[NSString stringWithFormat:@"%@,%@",[arrayData objectAtIndex:[picker selectedRowInComponent:0]],[minData objectAtIndex:[picker selectedRowInComponent:1]]];
}
@end But getting error like this
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }
and
libc++abi.dylib: terminating with uncaught exception of type NSException