Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.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 UITableViewCell&;输入框_Ios_Objective C - Fatal编程技术网

Ios UITableViewCell&;输入框

Ios UITableViewCell&;输入框,ios,objective-c,Ios,Objective C,我正在尝试用原型单元制作一个UITableView。现在我遇到了一个问题。我使用了3种不同的原型单元,其中2种有一个UITextField 我是这样做的,我已经对UITableViewCell子类化了2次,用于我的UITextFields的输出,以便从字段中获取信息 我做得对吗?还是我需要重做我的方法 这是我的代码[更新]: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndex

我正在尝试用原型单元制作一个UITableView。现在我遇到了一个问题。我使用了3种不同的原型单元,其中2种有一个UITextField

我是这样做的,我已经对UITableViewCell子类化了2次,用于我的UITextFields的输出,以便从字段中获取信息

我做得对吗?还是我需要重做我的方法

这是我的代码[更新]:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier;

    switch (indexPath.section) {
        case 0:{
            CellIdentifier = @"nameCell";
            naamCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[naamCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }

            [cell setSelectionStyle: UITableViewCellSelectionStyleNone];

            return cell;
            break;
        }

        default:{
            if(indexPath.row == [[_diceArray objectAtIndex:indexPath.section]count]){
                CellIdentifier = @"addCell";

            }else{
                CellIdentifier = @"optionCell";
                optionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

                if (cell == nil) {
                    cell = [[optionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                }
                [[cell optionCell] setText:[NSString stringWithFormat:@"%@", [[_diceArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]]] ;
                [cell setSelectionStyle: UITableViewCellSelectionStyleNone];

                return cell;
            }

            break;
        }
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    [cell setSelectionStyle: UITableViewCellSelectionStyleNone];

    return cell;
}
编辑:

下面是正在发生的事情的图片。所以我有两个部分。在我的文本字段中添加了两个内容。从第2节中删除一项。UITextField中的内容转到第3节,不会被删除:

编辑2: 我已经更新了代码。因此,人们可以动态编辑UITextField。我想我已经到了,用数组中的字符串测试了它,然后Cell.textfield.text=节索引中数组中的文本


现在我需要找到一种方法,用户可以自己添加文本,当按下或更改textfield时,文本get保存到我的数组中,然后执行[Table ReloadData];或者这不是正确的方法吗?

我想我终于明白了

需要实施这一点:

- (void) textFieldDidEndEditing:(UITextField *)textField {
    UIView* v = textField;

    do {
        v = v.superview;
    } while (![v isKindOfClass: [UITableViewCell class]]);
    optionCell* cell = (optionCell*)v;

    NSIndexPath* ip = [self._tabel indexPathForCell:cell];

    if (![textField.text isEqual:[[_diceArray objectAtIndex:ip.section] objectAtIndex:ip.row]]) {
        [[_diceArray objectAtIndex:ip.section] setObject:textField.text atIndex:ip.row];
    }
}

当你说你已经对你的单元格进行了子分类时,你是否为每个单元格创建了一个单独的nib文件?因为如果是这种情况,您可能需要注册NIB,可能是在viewDidLoad方法中。另外,原型单元在故事板中是否每个都有不同的标识符?我已经在我的故事板中设置了原型单元,给了它一个自定义类,并给了它不同的标识符。问题并不明显。是不是有些东西没有按你期望的方式工作?你提到的问题是什么?它不太好用。当我在第2节中添加2个值时。然后再次删除它们,将行添加到第3节,它们将重新出现在那里。在tableViewCell中显示的是静态值还是动态值。