Iphone UITableViewCell中的UIPickerView:显示特定单元格中的值时出现问题

Iphone UITableViewCell中的UIPickerView:显示特定单元格中的值时出现问题,iphone,uipickerview,Iphone,Uipickerview,我正在UITableView中使用UIPickerView来拾取整数值。我不知道如何设置特定单元格中标签的值。下面是我的代码: -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell; cell = [self.mTi

我正在UITableView中使用UIPickerView来拾取整数值。我不知道如何设置特定单元格中标签的值。下面是我的代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell;
cell = [self.mTicketTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell.bg.png"]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

lblType = [[UILabel alloc]initWithFrame:CGRectMake(10, 15, 90, 30)];
lblPrice = [[UILabel alloc]initWithFrame:CGRectMake(140, 15, 90, 30)];
lblSeat = [[UILabel alloc]initWithFrame:CGRectMake(232, 21, 52, 26)];
lblSeat.text = strSelected;
lblSeat.tag = indexPath.row+1;
lblSeat.textColor = [UIColor lightGrayColor];
lblSeat.textAlignment = NSTextAlignmentCenter;
lblSeat.backgroundColor = [UIColor clearColor];
UIButton *btnPicker = [UIButton buttonWithType:UIButtonTypeCustom];
[btnPicker setImage:[UIImage imageNamed:@"drop_down.png"] forState:UIControlStateNormal];
[btnPicker addTarget:self action:@selector(pickseats:) forControlEvents:UIControlEventTouchUpInside];
btnPicker.frame = CGRectMake(232, 20, 80, 30);

self.mPickerView = [[UIPickerView alloc] init];
self.mPickerView.frame = CGRectMake(228, 100, 90, 60); 
self.mPickerView.showsSelectionIndicator = YES;
self.mPickerView.delegate = self;
self.mPickerView.dataSource = self;
[self.mPickerView setNeedsLayout];
self.mPickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
self.mPickerView.hidden = TRUE;
[self.view addSubview:self.mPickerView];

lblType.text = [arrType objectAtIndex:indexPath.row];
if([arrCost count] == 0)
{
    lblPrice.text = @"0";
}
else{
lblPrice.text = [arrCost objectAtIndex:indexPath.row];
}
[cell addSubview:lblType];
[cell addSubview:lblPrice];
[cell addSubview:btnPicker];
[cell addSubview:lblSeat];

return cell;
}

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

-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 10;
}

-(NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [numbers objectAtIndex:row];
}

-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
strSelected = [numbers objectAtIndex:row];
NSLog(@"str selection:%@", strSelected);
self.mPickerView.hidden = TRUE;
[self.mTicketTable reloadData];
}
请为以上内容提供指导


提前感谢。

根据我的说法,您可以做的是:

首先,将标签分配给您的btnPicker和lblSeat

btnPicker.tag = indexPath.row;
lblSeat.tag = 11111;
然后在pickerView的didSelectRow方法中将所选值分配给数组

-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    int index = pickerView.tag;
    strSelected = [numbers objectAtIndex:row];
    NSIndexPath *path = [NSIndexPath indexPathForRow:index inSection:0];

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];

    for (UIView* tempView in [cell subviews]) {
        if ([tempView isKindOfClass:[UILabel class]]) {
            if (tempView.tag == 11111) {
                UILabel *lblTemp = (UILabel *)tempView;
                lblTemp.text = strSelected;
                break;
            }
        }
    }

    self.mPickerView.hidden = TRUE;
}
更换拣选座椅方法:

-(void)pickseats:(id)sender
{
    UIButton *btn = (UIButton *) sender;
    self.mPickerView.tag = btn.tag;
    self.mPickerView.hidden = FALSE;
}
我想这会管用的。如果不是的话,请告诉我。
THNKS.

这是什么[self.view addSubview:self.mPickerView];如果(cell==nil){cell=[[uitableViewCellAlloc]initWithStyle:uitableViewCellStyleDefaultReuseIdentifier:CellIdentifier];}其他{cell=[[uitableViewCellAlloc]initWithStyle:uitableViewCellStyleDefaultReuseIdentifier:CellIdentifier];}您正在self中添加pickerview。。。那不行。@iPhone:现在来看看。。。我已经编辑过了。。。。对于自定义单元格,我之前编写的内容将起作用……但现在尝试编辑一个……我认为存在一些与索引相关的问题,您在“UITableViewCell*cell”行中使用ARC进行int index=PICKERVEW.tag错误隐式转换到NSIndexPath的方式是不允许的。这是可以的,但它只更新最后一个单元格中的值,单击按钮时,我正在使用“通过”按钮。将显示选择器视图,并更新单击按钮所在单元格的值。请检查按钮是否有问题。你能为我提供你的项目,以便我能为你提供准确的解决方案吗?因为我不是从你的代码中得到的。这很简单,伙计,我说的是上面的活动应该在点击按钮时完成,在tableview中有一个UIButton,带有标签和选择器视图。单击按钮单击哪个按钮,该单元格的标签将被更新。如果有什么不清楚的,请询问。