Iphone UITableView单元格上的Pickerview值

Iphone UITableView单元格上的Pickerview值,iphone,ios,uitableview,uipickerview,Iphone,Ios,Uitableview,Uipickerview,在我的应用程序中,我实现了如下功能,Tabelview单元格包含两个按钮,单击它会显示选择器视图,当我选择选择器值时,它不会反映在uitabelview对应的cell.label上,这里是代码 Tableview单元 if(tableView.tag==25) { static NSString *simpleTableIdentifier = @"ordercel"; ordercel *cell = (ordercel *)[tableView

在我的应用程序中,我实现了如下功能,Tabelview单元格包含两个按钮,单击它会显示选择器视图,当我选择选择器值时,它不会反映在uitabelview对应的cell.label上,这里是代码

Tableview单元

    if(tableView.tag==25)
    {
        static NSString *simpleTableIdentifier = @"ordercel";
        ordercel *cell = (ordercel *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
        if (cell == nil)
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ordercel" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }
        cell.pimg.image=[arr objectAtIndex:indexPath.row];
        cell.sizlb.text=@"45";
        cell.qtylb.text=[qtyary objectAtIndex:indexPath.row];
        [cell.contentView addSubview:lbl1];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = indexPath.row+2000;
        [button addTarget:self action:@selector(BtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        button.backgroundColor=[UIColor clearColor];
        button.frame = CGRectMake(130, 20 , 70, 35);
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cell addSubview:button];

        UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
        button1.tag = indexPath.row+4000;
        [button1 addTarget:self action:@selector(sizPressed:) forControlEvents:UIControlEventTouchUpInside];
        button1.backgroundColor=[UIColor clearColor];
        button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button1.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        button1.frame = CGRectMake(230, 20 , 70, 35);
        [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cell addSubview:button1];
        return cell;
    }
按钮法

-(void)BtnPressed:(UIButton*)sender
{
    [self createActionSheet];
    pickerType = @"qtypicker";
    UIPickerView *chPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
    chPicker.tag=sender.tag-2000;
    chPicker.dataSource = self;
    chPicker.delegate = self;
    chPicker.showsSelectionIndicator = YES;
    [actionSheet addSubview:chPicker];
}
选择器视图代码

 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
 }

    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
    if ([pickerType isEqualToString:@"qtypicker"])
    {
        counti = [array count];
    }
    if ([pickerType isEqualToString:@"sizepicker"])
    {
        counti = [array1 count];
    }
    return counti;
}

    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSString *string;
    if ([pickerType isEqualToString:@"qtypicker"])
    {
        string = [array objectAtIndex:row];
    }
    if ([pickerType isEqualToString:@"sizepicker"])
    {
        string = [array1 objectAtIndex:row];
    }
    return string;
    }
    - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component      {
    return 300;
    }

    - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    UITableViewCell *owningCell = (UITableViewCell*)[thePickerView superview];
    NSIndexPath *pathToCell = [tabvu indexPathForCell:owningCell];
    int index1=thePickerView.tag;//= thePickerView.tag-2000;
    if ([pickerType isEqualToString:@"qtypicker"])
    {
         UILabel *obj=((UILabel *)[self.view viewWithTag:index1+1000]);
         obj.text = [array objectAtIndex:row];
        [qtyary addObject:obj.text];
        [tabvu reloadData];
    }
    if ([pickerType isEqualToString:@"sizepicker"])
    {

    }
    }

如何获取选定单元格上的选定选取器值。我应该在代码中做什么更改?请帮助我将其整理出来。

您的代码很难阅读。但这应该是方法

pickerView:(UIPickerView *)thePickerView didSelectRow 

方法更新数组对象
[qtyary objectAtIndex:indexath.row]
。然后调用
[tableView reloadData]
这将更新您的
cell.qtylb.text
。对于其他标签,您还需要一个将要更新的数组。我希望这能起作用。

试着换一行

UITableViewCell *owningCell = (UITableViewCell*)[thePickerView superview];  

如果您有用于打开按钮的自定义单元格,则应使用自定义单元格而不是UITableViewCell的单元格实例

并尝试在这种情况下打印日志

    if ([pickerType isEqualToString:@"qtypicker"])
{
     UILabel *obj=((UILabel *)[self.view viewWithTag:index1+1000]);
     obj.text = [array objectAtIndex:row];
    [qtyary addObject:obj.text];
    [tabvu reloadData];
}

返回的对象。将NSLog应用于obj。

是否已正确连接数据源和委托?为什么选取器高度为0?试着在地板上加一个高度picker@Bhargavi是的,我已经接通了
    if ([pickerType isEqualToString:@"qtypicker"])
{
     UILabel *obj=((UILabel *)[self.view viewWithTag:index1+1000]);
     obj.text = [array objectAtIndex:row];
    [qtyary addObject:obj.text];
    [tabvu reloadData];
}