0
votes

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.

1
what you want ,why you create each cell UIPickerView and NSMutableArray ?Dhaval Bhadania
I am listing shopping cart in this table. And I want to update the quantity(or Color) of the product in the cart.Vinod

1 Answers

1
votes

Try this...

UITableViewCell *cell = (UITableViewCell *)[thePickerView superview];
NSIndexPath *path = [self.tableView indexPathForCell:cell];
NSLog(@"indexPathForSelectedRow  %@", path);