3

I have a table view with custom cell.On my custom cell, I have a label and textView and I want to get data from textView to save in feedBack button. When I add txtView in my data array, I get custom cell twice. How to remove this issue

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

}
Gordon
  • 312,688
  • 75
  • 539
  • 559
Noor
  • 2,071
  • 19
  • 28

3 Answers3

4

First get the cell at particular index and then get view from it and then textview

Use following function to get cell

[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]
Payal
  • 116
  • 3
2

// i think it will be usefull for you, try this

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

    nslog(@"%@",cellsuperView.txtViewAnswer.text);
}
Lokesh Chowdary
  • 816
  • 5
  • 22
2
- (void)textViewDidEndEditing:(UITextView *)textView
{
   FeedbackQuestionDC *feedBack = [dataArray objectAtIndex:textView.tag];
   feedBack.FeedbackQuestionDC_Answers=textView.text;
   [dataArray addObject:feedBack]; //REMOVE THIS LINE 
   [myTableView reloadData];
}

See the code above remove the line I suggested, you don't need to add the object again into array, it has already been updated using the reference of the object from dataArray.

Hope this helps..

iphonic
  • 12,615
  • 7
  • 60
  • 107