lantianyiming 2013-04-03 02:52 采纳率: 0%
浏览 2974
已采纳

提出自定义单元中的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;
}
  • 写回答

2条回答

  • ce_la_vie 2013-04-03 05:20
    关注
    - (void)textViewDidEndEditing:(UITextView *)textView
    {
       FeedbackQuestionDC *feedBack = [dataArray objectAtIndex:textView.tag];
       feedBack.FeedbackQuestionDC_Answers=textView.text;
       [dataArray addObject:feedBack]; //REMOVE THIS LINE 
       [myTableView reloadData];
    }
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题