I have a table view and few custom cells.in one custom cell there is a picker view.I need to load the data to the picker view at cellForRowAtIndexPath
this is my cellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifierOne = @"detailCell";
FlightUserTableViewCell *detailcell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierOne];
NSString *cellIdentifierTwo = @"detailCelltwo";
FlightUserSecondTableViewCell *detailcelltwo = [tableView dequeueReusableCellWithIdentifier:cellIdentifierTwo];
if (indexPath.section == 0) {
if (indexPath.row ==0) {
//detailcell.titlepickerView **here i want to load the data **
return detailcell;
}
return detailcelltwo;
}
return detailcelltwo;
}
how can I do that.I know if we load data to picker view normally we have to implement it's delegate methods like below.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [cabinArray count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [cabinArray objectAtIndex:row];
}
so how can I do that for the picker view inside the custom cell.hope your help.
as the answers, I have implemented delegate methods inside the custome tableview cell like this
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [leadandadultTitle count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [leadandadultTitle objectAtIndex:row];
}
then inside the cellForRowAtIndexpath I have implemented like this.
if (indexPath.section == 0) {
NSString *cellIdentifierOne = @"detailCell";
FlightUserTableViewCell *detailcell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierOne];
if (indexPath.row ==0) {
if([traveller isEqualToString:@"LEAD"])
{
detailcell.leadandadultTitle = leadandadultTitle;
detailcell.titlepickerView.delegate = self;
detailcell.titlepickerView.dataSource = self;
}
else
{
detailcell.leadandadultTitle = childandinfantTitle;
}
return detailcell;
}
Note :I tried with setting the delegate and datasource like above and also tried dragging the pickerview and selecte delegate and datasource but
numberOfComponentsInPickerView:]: unrecognized selector sent to instance this gives
cellForRowAtIndexPath:cellForRowAtIndexPath