我在表的UITableViewCell中有一个UITextView。UITextView的“可编辑”被关闭,这允许我将dataDetectorTypes设置为UIDataDetectorTypeAll,这正是我想要的。现在,该应用程序会检测到用户何时触摸UITextView中的链接,并执行相应的操作。
当用户触摸没有链接的UITextView的一部分时,问题就出现了。我希望调用UITableView委托中的didSelectRowAtIndexPath。但事实并非如此,因为即使在没有检测到链接的情况下,UITextView也会捕获触摸。
我的第一个猜测是将UITextView上的userInteractionEnabled设置为NO。这意味着将调用didSelectRowAtIndexPath,但随后UITextView无法检测到链接。这是个第22条军规。
有什么办法解决这个问题吗?
谢谢你的帮助。
发布于 2012-07-05 17:40:17
也许你可以试着在响应器链上传递触摸屏。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
}
发布于 2015-10-14 19:35:22
覆盖所有四个UIResponder
触摸处理程序以转发到文本视图的superview。
头文件声明:“一般来说,所有进行自定义触摸处理的响应器都应该覆盖所有这四种方法。…你必须处理取消的触摸,以确保应用程序中的正确行为。如果不这样做,很可能会导致不正确的行为或崩溃。”
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)
}
}
https://stackoverflow.com/questions/11347727
复制相似问题