【问题标题】:issue enabling dataDetectorTypes on a UITextView in a UITableViewCell在 UITableViewCell 中的 UITextView 上启用 dataDetectorTypes 的问题
【发布时间】:2012-07-06 01:23:36
【问题描述】:

我在表格的 UITableViewCell 中有一个 UITextView。 UITextView 的“可编辑”已关闭,这允许我将 dataDetectorTypes 设置为 UIDataDetectorTypeAll,这正是我想要的。该应用现在会检测用户何时触摸 UITextView 中的链接,并执行相应的操作。

当用户触摸没有链接的部分 UITextView 时,就会出现问题。我希望调用 UITableView 委托中的 didSelectRowAtIndexPath 。但事实并非如此,因为 UITextView 会捕获触摸,即使未检测到链接也是如此。

我的第一个猜测是将 UITextView 上的 userInteractionEnabled 设置为 NO。这意味着 didSelectRowAtIndexPath 将被调用,但是 UITextView 无法检测到链接。这是第 22 条规则。

关于如何解决这个问题的任何想法?

感谢您的帮助。

【问题讨论】:

    标签: iphone uitableview uitextview datadetectortypes


    【解决方案1】:

    也许您可以尝试将修饰传递给响应者链。

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       [super touchesBegan:touches withEvent:event];
    }
    

    【讨论】:

    • 我必须从那里获取单元格,然后我必须从单元格中调用 didSelectRowAtIndexPath,但它有效!谢谢。
    【解决方案2】:

    覆盖所有四个UIResponder 触摸处理程序以转发到文本视图的超级视图。

    头文件声明“通常,所有进行自定义触摸处理的响应者都应该覆盖所有这四个方法。......您必须处理取消的触摸以确保应用程序中的正确行为。不这样做很可能导致不正确的行为或崩溃。”

    class MyTextView: UITextView {
    
        override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
            self.superview?.touchesBegan(touches, withEvent: event)
        }
    
        override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
            self.superview?.touchesMoved(touches, withEvent: event)
        }
    
        override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
            self.superview?.touchesEnded(touches, withEvent: event)
        }
    
        override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
            self.superview?.touchesCancelled(touches, withEvent: event)
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2020-03-19
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多