Reputation: 675
I have a UIPickerView on each row of my UITableViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CartCell *cell = (CartCell *)[tableView dequeueReusableCellWithIdentifier:@"CartCell"];
Cart *cart = (self.carts)[indexPath.row];
cell.productnameLabel.text = cart.productname;
cell.priceLabel.text = cart.price;
picker = [[UIPickerView alloc]initWithFrame:CGRectMake(70, 0, 100, 40)];
[picker setDelegate:self];
arrayColors = [[NSMutableArray alloc] init];
[arrayColors addObject:@"Red"];
[arrayColors addObject:@"Orange"];
[arrayColors addObject:@"Yellow"];
[arrayColors addObject:@"Green"];
[arrayColors addObject:@"Blue"];
[arrayColors addObject:@"Indigo"];
[arrayColors addObject:@"Violet"];
[cell addSubview:picker];
return cell;
}
and I have the didSelectRow for the picker
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"Selected Color: %@. Index of selected color: %i", [arrayColors objectAtIndex:row], row);
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
NSLog(@"indexPathForSelectedRow %@", path);
}
But I am getting the path vaue as null. How to get UIPickerView value in UITableView. I need the picker value of each row.
Upvotes: 0
Views: 1269
Reputation: 1340
Try this...
UITableViewCell *cell = (UITableViewCell *)[thePickerView superview];
NSIndexPath *path = [self.tableView indexPathForCell:cell];
NSLog(@"indexPathForSelectedRow %@", path);
Upvotes: 1