在我的表視圖中包含一個自定義單元,其中有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;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
FeedbackQuestionDC *feedBack = [dataArray objectAtIndex:textView.tag];
feedBack.FeedbackQuestionDC_Answers=textView.text;
[dataArray addObject:feedBack]; //REMOVE THIS LINE
[myTableView reloadData];
}
移除上述代碼中我建議的那行,不需要在數組中重復添加對象。在使用dataArray相關對象中已經更新過了。