Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有不同对象的动态UITableview_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 具有不同对象的动态UITableview

Ios 具有不同对象的动态UITableview,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个带有自定义单元格的表视图,其中包含UITextField、UIDatePicker、UIPickerView。 在我的方法cellForRowAtIndexPath中,我为每一行设置了它的行为。 但我意识到,当我点击顶部的第一行时,一切都很好,相反,当我向下滚动表格并更改底部的值时,例如,我在第7行输入的值被插入到第8行,依此类推,在较低的行中 实际上,当我滚动表格时,它会造成行索引的混乱 或者,例如il UITableViewCellAccessoryDisclosureIndicat

我有一个带有自定义单元格的表视图,其中包含UITextField、UIDatePicker、UIPickerView。 在我的方法cellForRowAtIndexPath中,我为每一行设置了它的行为。 但我意识到,当我点击顶部的第一行时,一切都很好,相反,当我向下滚动表格并更改底部的值时,例如,我在第7行输入的值被插入到第8行,依此类推,在较低的行中 实际上,当我滚动表格时,它会造成行索引的混乱 或者,例如il UITableViewCellAccessoryDisclosureIndicator,在重新加载表格时,表格将其分配给第2行,而不是将其分配给第9行

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    UITextField *text1 = (UITextField *)[cell viewWithTag:100];
    UILabel *text2 = (UILabel *)[cell viewWithTag:200];
    text1.text = [valuesArray objectAtIndex:indexPath.row];
    text2.text = [titlesArray objectAtIndex:indexPath.row];

    switch (indexPath.row) {
        case 0:  
            {
                text1.delegate = self;
                text1.tag = indexPath.row;
            }
            break;

        case 1: 
            {
                activityPicker = [[UIPickerView alloc] init];
                activityPicker.delegate = self;
                activityPicker.tag = indexPath.row;
                text1.delegate = self;
                text1.inputView  = activityPicker;
            }
            break;

        case 2: 
            {
                datePicker = [[UIDatePicker alloc] init];
                datePicker.datePickerMode = UIDatePickerModeDate;
                [datePicker addTarget:self action:@selector(onDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
                text1.delegate = self;
                text1.inputView = datePicker;
                datePicker.tag = indexPath.row;
            }
            break;

        case 3: 
            {
                datePicker = [[UIDatePicker alloc] init];
                datePicker.datePickerMode = UIDatePickerModeTime;
                [datePicker addTarget:self action:@selector(onDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
                text1.delegate = self;
                text1.inputView = datePicker;
                datePicker.tag = indexPath.row;
                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                [dateFormatter setDateFormat:@"HH:mm"];
                [datePicker setDate: [dateFormatter dateFromString:text1.text]];
            }
            break;

        case 4:  
            {
                activityPicker = [[UIPickerView alloc] init];
                activityPicker.delegate = self;
                activityPicker.tag = indexPath.row;
                NSString *km = [text1.text substringToIndex:[text1.text length]-3];
                int numkm = [km intValue] - 1;
                [activityPicker selectRow:numkm inComponent:0 animated:YES];
                text1.delegate = self;
                text1.inputView  = activityPicker;
            }
            break;

        case 5: 
            {
                activityPicker = [[UIPickerView alloc] init];
                activityPicker.delegate = self;
                activityPicker.tag = indexPath.row;
                text1.delegate = self;
                text1.inputView = activityPicker;
            }
            break;

        case 6: 
            {
                activityPicker = [[UIPickerView alloc] init];
                activityPicker.delegate = self;
                activityPicker.tag = indexPath.row;
                if ([text1.text isEqualToString:[animalsArray objectAtIndex:0]])
                    [activityPicker selectRow:0 inComponent:0 animated:YES];
                else
                    [activityPicker selectRow:1 inComponent:0 animated:YES];

                text1.delegate = self;
                text1.inputView = activityPicker;
            }
            break;

        case 7:  
                text1.delegate = self;
                text1.tag = indexPath.row;
            }
            break;

        case 8:  
            {
                activityPicker = [[UIPickerView alloc] init];
                activityPicker.delegate = self;
                activityPicker.tag = indexPath.row;
                if ([text1.text isEqualToString:[privacyArray objectAtIndex:0]])
                    [activityPicker selectRow:0 inComponent:0 animated:YES];
                else
                    [activityPicker selectRow:1 inComponent:0 animated:YES];

                text1.delegate = self;
                text1.inputView = activityPicker;
            }
            break;

        case 9:  
        {
            text1.enabled = NO;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
            break;

        default:
            break;
    }

    return cell;
}

您的问题是对所有行使用相同的单元格标识符
“cell”
。这将导致您已经为某个
配置的单元格重新加载并重新用于另一行

假设您只有这10个单元设计,您可以:

NSString*        identifier = [NSString stringWithFormat: @"Cell-%d", indexPath.row];
UITableViewCell* cell       = [tableView dequeueReusableCellWithIdentifier:identifier
                                                              forIndexPath:indexPath];

这样,
dequeueReusableCellWithIdentifier
将只返回先前为当前
indexPath

创建的单元格。您的问题是对所有行使用相同的单元格标识符
“单元格”
。这将导致您已经为某个
配置的单元格重新加载并重新用于另一行

假设您只有这10个单元设计,您可以:

NSString*        identifier = [NSString stringWithFormat: @"Cell-%d", indexPath.row];
UITableViewCell* cell       = [tableView dequeueReusableCellWithIdentifier:identifier
                                                              forIndexPath:indexPath];

这样,
dequeueReusableCellWithIdentifier
将只返回先前为当前
indexPath

创建的单元格,但如何在情节提要上设置单元格标识符?是的,我知道如何在情节提要中连接原型单元格,但在这种情况下,我需要编写动态单元格标识符。。。。1号牢房2号牢房还是我必须用不同的方式制作?问题是,我必须在故事板上设置单元标识符,但如何在故事板上设置单元标识符?是的,我知道如何连接故事板中的原型单元,但在这种情况下,我需要编写动态单元标识符。。。。1号牢房2号牢房还是我必须用不同的方式制作?问题是我必须在情节提要上设置一个单元标识符,但是