检测底层UITableViewCell上的触摸并点击UITextview的属性文本

时间:2014-06-18 18:21:51

标签: ios objective-c uitableview uitextview textkit

我使用附加到UITextView的{​​{1}},其配置如下所示:

UITableViewCell

现在,我想使用文本工具包功能来检测我的属性文本(http://www.raywenderlich.com/48001/easily-overlooked-new-features-ios-7#textViewLinks)和cell.topicAndDescriptionTextView = [[UITextView alloc] initWithFrame:frame]; cell.topicAndDescriptionTextView.tag = 1; cell.topicAndDescriptionTextView.attributedText = attrText; cell.topicAndDescriptionTextView.scrollEnabled = NO; cell.topicAndDescriptionTextView.editable = NO; cell.topicAndDescriptionTextView.textContainer.lineFragmentPadding = 0; cell.topicAndDescriptionTextView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0); cell.topicAndDescriptionTextView.backgroundColor =[UIColor clearColor]; [cell.topicAndDescriptionTextView setUserInteractionEnabled:YES]; cell.topicAndDescriptionTextView.dataDetectorTypes = UIDataDetectorTypeAll; 中自定义链接的点击,以便在客户点击{{1}中的某个位置时识别向下钻取}没有自定义链接。

不幸的是- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath让textview吞下所有触摸。实现这一目标的最佳方法是什么?我想过编写一个自定义的UITableViewCell类,并使用[UITextView setUserInteractionEnabled:YES]个委托,但是如何确定超级类是否已经处理了链接上的新闻并阻止了向下钻取?

THX,

2 个答案:

答案 0 :(得分:1)

如果返回的视图是用于链接按钮的视图,我会尝试覆盖hitTest并仅返回命中视图。在其他情况下返回零。然后触摸传递到表视图,滚动继续工作。

答案 1 :(得分:0)

我找到了解决方案。我创建了自定义UITextView类并覆盖了touchesBegan。只有在UITextView中没有单击链接时才会调用Touches Began。我玩了hitTest,但是hitTest一直被调用,我无法确定是否在UITextView中触摸了链接。