Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell内的UITextView-如果未单击链接,请触摸浏览_Ios_Uitableview_Touch_Uitextview_Datadetectortypes - Fatal编程技术网

Ios UITableViewCell内的UITextView-如果未单击链接,请触摸浏览

Ios UITableViewCell内的UITextView-如果未单击链接,请触摸浏览,ios,uitableview,touch,uitextview,datadetectortypes,Ios,Uitableview,Touch,Uitextview,Datadetectortypes,我试图利用UITextView的优势,将数据检测器类型放在一个本身可点击的TableViewCell中 唯一的问题是,我需要UITextView的链接是可点击的,因此userInteractionEnabled=YES,不幸的是,这将阻止任何接触到UITableViewCell的行为 当然UITextView不能编辑,我还将其子类化,拒绝将其作为第一响应者,以避免在其中选择文本 我唯一需要的是,检测如果用户触摸UITextView,检查它是否是链接,然后打开链接,否则重定向UITableView

我试图利用UITextView的优势,将数据检测器类型放在一个本身可点击的TableViewCell中

唯一的问题是,我需要UITextView的链接是可点击的,因此userInteractionEnabled=YES,不幸的是,这将阻止任何接触到UITableViewCell的行为

当然UITextView不能编辑,我还将其子类化,拒绝将其作为第一响应者,以避免在其中选择文本

我唯一需要的是,检测如果用户触摸UITextView,检查它是否是链接,然后打开链接,否则重定向UITableViewCell上的触摸

你知道怎么做吗


很像twitter应用程序(我们可以点击行,也可以点击链接…

我知道这个问题很久以前就被问过了,但是对于一些应用程序来说,仍然非常需要这种行为来拥有一个带有UIDataDetector的可点击单元格

下面是我为适应UITableView中的这种特殊行为而创建的UITextView子类

-(id) initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = self;
    }
    return self;
}

- (BOOL)canBecomeFirstResponder {
    return NO;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UIView *obj = self;

    do {
        obj = obj.superview;
    } while (![obj isKindOfClass:[UITableViewCell class]]);
    UITableViewCell *cell = (UITableViewCell*)obj;

    do {
        obj = obj.superview;
    } while (![obj isKindOfClass:[UITableView class]]);
    UITableView *tableView = (UITableView*)obj;

    NSIndexPath *indePath = [tableView indexPathForCell:cell];
    [[tableView delegate] tableView:tableView didSelectRowAtIndexPath:indePath];
}

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    return YES;
}
您可以修改此项以满足您的需要


希望这对某人有所帮助。

你可以看看我的新答案可能与@jrc重复我的答案似乎是一个更完整的解决方案。@jrc你是对的,下次我找到更好的解决方案时,我应该把它留给我自己。。。