[ios]停止从一个 UITextView 添加到另一个原型单元格内输入的文本

发布时间: 2015/7/12 1:49:28
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有一个奇怪的问题,我不能弄个水落石出。我有 UITableView 根据内容可变的数组中存储的各种原型细胞。它使用起来有点像这样:

    if([currentHandout.content[indexPath.row - 3] isKindOfClass: [objHandoutSubtitle class]]){
        cellId =@"CellHandoutSubtitle";
        cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];

        ..
    }
    else if([currentHandout.content[indexPath.row  - 3] isKindOfClass: [objHandoutParagraph class]]){
        cellId =@"CellHandoutGeneral";
        cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];

        ..
    }
    else if([currentHandout.content[indexPath.row  - 3] isKindOfClass: [objHandoutQuote class]]){
        cellId =@"CellHandoutQuote";
        cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];

        ..
    }
    else if([currentHandout.content[indexPath.row  - 3] isKindOfClass: [objHandoutSimpleQuestion class]]){
        cellId =@"CellHandoutSimpleQuestion";
        cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];

        UILabel *questionLabel = (UILabel *)[cell viewWithTag:1];
        questionLabel.text = questionText;

        UITextView *theTextView = (UITextView *)[cell viewWithTag:2];
        theTextView.tag = indexPath.row + 100;
            theTextView.delegate = self;

        ..
    }

问题是当我向 UITextView 它重复用户输入到另一单元格中进一步它下面,如图所示,所示有谁知道为什么 CellHandoutSimpleQuestion 单元格中添加文本?

repeating answer

解决方法 1:

因为您要重用的单元格 UITextView,那发生。为了避免那你需要在你的模型的属性中存储 UITextView 文本和还在最后一点上设置该文本

...
else if([currentHandout.content[indexPath.row  - 3] isKindOfClass: [objHandoutSimpleQuestion class]]){
    cellId =@"CellHandoutSimpleQuestion";
    cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];

    UILabel *questionLabel = (UILabel *)[cell viewWithTag:1];
    questionLabel.text = questionText;

    UITextView *theTextView = (UITextView *)[cell viewWithTag:2];
    theTextView.tag = indexPath.row + 100;
        theTextView.delegate = self;
        the.TextView.text = yourModelForTheCell.textViewText;
    ..
}

如果你有需要支持编辑您必须更新上委托方法的对应的模型对象的属性textView:shouldChangeTextInRange:replacementText:

官方微信
官方QQ群
31647020