我有自定义单元格的表视图。在我的自定义单元格中,我有一个标签和textView,我想从textView获取数据以保存在feedBack按钮中。当我在我的数据数组中添加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;
}
答案 0 :(得分:4)
首先获取特定索引处的单元格,然后从中获取视图,然后查看textview
使用以下功能获取单元格
[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]
答案 1 :(得分:2)
//我认为这对你有用,试试这个
- (void)textViewDidEndEditing:(UITextView *)textView
{
feedBackCC *cellsuperView = (feedBackCC *)[textView superview];
nslog(@"%@",cellsuperView.txtViewAnswer.text);
}
答案 2 :(得分: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中对象的引用进行了更新。
希望这会有所帮助..