从UITextView转发到UITableViewCell

时间:2014-05-17 00:15:31

标签: ios uitableview uitextview

我在uitableviewcell中有一个UITextView,我只使用它来复制/粘贴内容。但是,对textView的单击不会转发到tableViewCell。

有什么方法吗?

1 个答案:

答案 0 :(得分:2)

你可以这样做:

- (void)textTapped:(UITapGestureRecognizer *)recognizer
{
    // Get the text view from gesture recognizer or some delegate method
    UITextView *textView = (UITextView *)recognizer.view;

    UIView *cellToBeSelected = textView.superview;

    // Try to get the correct cell view according to received view hierarchical.
    while (![cellToBeSelected isKindOfClass:[UITableViewCell class]])
    {
        cellToBeSelected = [cellToBeSelected superview];
    }

    // Select the cell
    if (cellToBeSelected)
    {
        [self.tableView selectRowAtIndexPath:[self.tableView indexPathForCell:(UITableViewCell *)cellToBeSelected]
                                    animated:YES
                              scrollPosition:UITableViewScrollPositionNone];
    }
}