如何从iPhone自定义单元格的textView中获取文本

3

我有一个带有自定义单元格的表视图。在我的自定义单元格上,我有一个标签和文本视图,我想从文本视图中获取数据并保存在“反馈”按钮中。当我将txtView添加到我的数据数组中时,我会得到两个自定义单元格。如何解决这个问题?

- (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;

}
3个回答

4
首先获取特定索引处的单元格,然后从中获取视图,接着再获取文本视图。
使用以下函数获取单元格。
[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]

2

// 我认为这对你会有用,试试看

- (void)textViewDidEndEditing:(UITextView *)textView
{
    feedBackCC *cellsuperView = (feedBackCC *)[textView superview];

    nslog(@"%@",cellsuperView.txtViewAnswer.text);
}

2
- (void)textViewDidEndEditing:(UITextView *)textView
{
   FeedbackQuestionDC *feedBack = [dataArray objectAtIndex:textView.tag];
   feedBack.FeedbackQuestionDC_Answers=textView.text;
   [dataArray addObject:feedBack]; //REMOVE THIS LINE 
   [myTableView reloadData];
}

请参考上面的代码,删除我建议的那一行。您不需要将对象再次添加到数组中,因为它已经使用dataArray中的对象引用进行更新了。

希望对您有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接