【问题标题】:Forward taps from UITextView to UITableViewCell从 UITextView 转发点击到 UITableViewCell
【发布时间】:2014-05-17 00:15:30
【问题描述】:

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

有没有办法解决这个问题?

【问题讨论】:

  • 您可以添加轻击手势来调用从UITableViewCell 子类中调用selectRowAtIndexPath: 的方法。见here

标签: ios uitableview uitextview


【解决方案1】:

你可以这样做:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多