开发者社区> 问答> 正文

提出自定义单元中的textView内容

在我的表视图中包含一个自定义单元,其中有label和textView,我想提出textview的数据保存到feedBack按钮中,当添加txtView到数据数组中,得到重复的自定义cell。

这个问题应该怎么解决呢?

- (void)textViewDidEndEditing:(UITextView *)textView
{
    FeedbackQuestionDC *feedBack = [dataArray objectAtIndex:textView.tag];
    feedBack.FeedbackQuestionDC_Answers=textView.text;
    [dataArray addObject:feedBack];
    [myTableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *simpleTableIdentifier = @"Feed Back";

    feedBackCC *cell = (feedBackCC *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        UIViewController *c = [[UIViewController alloc] initWithNibName:@"feedBackCC" bundle:nil];
        cell = (feedBackCC *) c.view;}
    cell.textLabel.font = [UIFont boldSystemFontOfSize:15.0];
    FeedbackQuestionDC *feedBack = [dataArray objectAtIndex:[indexPath row]];
         cell.lblQuestion.text = feedBack.FeedbackQuestionDC_QuestionText;
    cell.txtViewAnswer.tag=indexPath.row;
    cell.txtViewAnswer.text=feedBack.FeedbackQuestionDC_Answers;
    cell.txtViewAnswer.delegate=self;
    return cell;
}

展开
收起
爵霸 2016-03-24 09:33:16 1842 0
1 条回答
写回答
取消 提交回答
  • - (void)textViewDidEndEditing:(UITextView *)textView
    {
       FeedbackQuestionDC *feedBack = [dataArray objectAtIndex:textView.tag];
       feedBack.FeedbackQuestionDC_Answers=textView.text;
       [dataArray addObject:feedBack]; //REMOVE THIS LINE 
       [myTableView reloadData];
    }

    移除上述代码中我建议的那行,不需要在数组中重复添加对象。在使用dataArray相关对象中已经更新过了。

    2019-07-17 19:11:55
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
动态、高效,蚂蚁动态卡片的内核逻辑 立即下载
重新定义计算的边界 立即下载
快速变化背景下,组织如何保持过程的稳定性? 立即下载