我在UIViewController的视图中有一个UITableView作为子视图。我知道我可以通过覆盖来检测触摸事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
}
但如果我触及ViewController
,它就不会在tableview
中检测到这些事件。正如其他人在本论坛中所建议的那样,我应该有一个自定义UITableView
并在其中添加上述行。我做到了,但viewController
仍未检测到触摸事件。有什么建议?感谢。
答案 0 :(得分:1)
经过几天的谷歌搜索,我终于找到了适合我的解决方案。关键是将响应者链传递给下一个响应者。例如,在触摸开始的情况下,添加以下行。 [self.nextResponder touchesBegan:touches withEvent:event]