【问题标题】:How to get text from textView from custom cell iphone如何从自定义单元格iphone的textView获取文本
【发布时间】:2013-04-02 07:59:49
【问题描述】:

我有一个带有自定义单元格的表格视图。在我的自定义单元格上,我有一个标签和 textView,我想从 textView 获取数据以保存在反馈按钮中。当我在我的数据数组中添加 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;

}

【问题讨论】:

    标签: iphone ios textview custom-cell


    【解决方案1】:

    首先获取特定索引处的单元格,然后从中获取视图,然后获取文本视图

    使用以下函数获取单元格

    [table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]
    

    【讨论】:

      【解决方案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 中对象的引用进行了更新。

      希望这会有所帮助..

      【讨论】:

        【解决方案3】:

        //我觉得对你有用,试试这个

        - (void)textViewDidEndEditing:(UITextView *)textView
        {
            feedBackCC *cellsuperView = (feedBackCC *)[textView superview];
        
            nslog(@"%@",cellsuperView.txtViewAnswer.text);
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-29
          • 1970-01-01
          相关资源
          最近更新 更多