0

在此处输入图像描述

我正在为自定义单元格中的 2 个文本字段使用选择器。在为一个字段选择选择器值时,它会重复一个部分中的所有行。我正在使用以下代码。我正在为该文本字段的自定义按钮操作设置选择器。

int pickerMoved=0;

-(IBAction)genderpickerbtnpressed:(id)sender {
    NSLog(@"genderpickerbtnpressed called ");
    UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Select your gender"
                                                        delegate:self
                                               cancelButtonTitle:@"Cancel"
                                          destructiveButtonTitle:nil
                                               otherButtonTitles:@"Select", nil];

    [asheet setTag:200];

    UIPickerView *statePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
    statePicker.delegate=self;

    statePicker.showsSelectionIndicator = YES;
    [statePicker setTag:11];
    [asheet addSubview:statePicker];
    [asheet showInView:[self.view superview]];
    [asheet setBounds:CGRectMake(0,0,320, 700)];
    [asheet setFrame:CGRectMake(0, 117, 320, 383)];
}



- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex != [actionSheet cancelButtonIndex]) {

        if(actionSheet.tag==200) {

            if(buttonIndex==0) {

                if(pickerMoved>0) {
                    NSLog(@"selected item is %d",pickerMoved);
                    NSLog(@"selected data is %@",[self.genderarray objectAtIndex:pickerMoved] );

                    self.savingsStr=[self.genderarray objectAtIndex:pickerMoved];
                } else {

                    NSLog(@"distanceArray object at index %@",[self.genderarray objectAtIndex:0]);
                    self.savingsStr=[self.genderarray objectAtIndex:0];
                }

            }
        }
        pickerMoved=0;
        [self.tripView reloadData];
    }



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTripViewCell *cell = (MyTripViewCell *) [tableView dequeueReusableCellWithIdentifier:@"acell"];

    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyTripViewCell" owner:self options:nil] objectAtIndex:0];

        cell=Tblcell;
    }

    if(indexPath.section == 0) {

        Passenger *temp = [appDelegate.ADULTS objectAtIndex:indexPath.row];

        NSLog(@"adults array count is %d",[appDelegate.ADULTS count]);
        cell.textfield.text = temp.name;

        cell.gendertextfield.text = self.savingsStr;
        cell.dobtextfield.text =self.datepickerstr;
        cell.gendertextfield.tag=indexPath.row;

        [savingsStr release];
        NSLog(@"temp.gender is ----- %@",temp.gender);

    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    return cell;
}

成人部分中性别文本字段的值重复。如何将选取器值复制到单元格。任何想法与我分享。谢谢。

4

1 回答 1

1

在你的cellForRow方法中,你有

if(indexPath.section == 0) 

我认为应该是

if(indexPath.row == 0) 

这样它只填充第一行,如果你想填充第一部分的第一行,你需要同时使用这两个条件。

于 2012-10-19T17:04:57.613 回答