Objective c 如何在UITableView中获取UIPickerView值

Objective c 如何在UITableView中获取UIPickerView值,objective-c,ios7,uitableview,uipickerview,Objective C,Ios7,Uitableview,Uipickerview,我在UITableViewController的每一行上都有一个UIPickerView - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CartCell *cell = (CartCell *)[tableView dequeueReusableCellWithIdentifier:@"CartCell"]; Cart *c

我在UITableViewController的每一行上都有一个UIPickerView

- (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;
}
我还有一排给采摘者的

- (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);

}
但我得到的路径值为null。 如何在UITableView中获取UIPickerView值。我需要每行的选择器值。

试试这个

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

你想要什么,为什么要创建每个单元格UIPickerView和NSMutableArray?我在这个表中列出了购物车。我还想更新购物车中产品的数量(或颜色)。indexPathForCell的null返回值也是如此。是因为自定义单元格吗?很抱歉,我没有提到我的sdk版本。这是ios。我从这个链接得到了解决方案,修改了代码-(void)pickerView:(UIPickerView*)pickerView没有选择row:(NSInteger)row component:(NSInteger)component{UIView*view=thePickerView;而(view!=nil&![视图是类的一种:[UITableViewCell类]){view=[视图超级视图];}UITableViewCell*单元格=(UITableViewCell*)视图;NSIndexPath*路径=[self.tableView indexPathForCell:cell];NSLog(@“indexPathForSelectedRow%@”,路径);NSLog(@“节为%d,行为%d”,路径为.section,路径为.row);}hmn。。。一切都很好,如果您使用CartCell代替UITableViewCell会更好。在line while(view!=nil&&![view iskindof class:[UITableViewCell class]])中,我尝试了CartCell*cell=(CartCell*)[thePickerView superview];但同样的零结果出现了。但它可以在运行循环时使用UIView。不知道为什么它不能与CartCell一起工作。