对于区域中的所有行,选取器值在文本字段中重复?

时间:2012-10-19 15:39:37

标签: iphone objective-c ios xcode uipickerview

enter image description here

我在自定义单元格中使用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;
}

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

1 个答案:

答案 0 :(得分:1)

使用您的cellForRow方法

if(indexPath.section == 0) 

我认为应该是

if(indexPath.row == 0) 

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