iPhone 中的 UITableViewController 类中未调用 TouchBegan 方法
如何在 UITableViewController 类中使用 touchesBegan: withEvent:
方法?
UITableViewController 是 UIViewController 类的子类。那么为什么该方法在 UITableViewController 中不起作用呢?
How can I use touchesBegan: withEvent:
method in UITableViewController class?
UITableViewController is a subclass of UIViewController class. So why the method does not works in UITableViewController?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到了类似的问题,并找到了一种不涉及 UITableView 子类化的不同方法。另一种方法是向 UITableViewController 的视图添加手势识别器。
我将此代码放在 UITableViewController 的 viewDidLoad 中:
并实现了事件处理程序:
我知道这个解决方案不使用 TouchBegan,但我发现这是针对同一问题的简单解决方案。
I had a similar problem, and found a different approach that doesn't involve subclassing UITableView. Another way to do this is to add a gesture recognizer to the UITableViewController's view.
I put this code in the UITableViewController's viewDidLoad:
And implemented the event handler:
I know this solution doesnt use touchesBegan, but I found it was a simple solution to the same problem.
TouchBegan 除了是 UIViewController 方法之外也是 UIView 方法。
要覆盖它,您需要子类化 UIView 或 UITableView 而不是控制器。
touchesBegan is a also UIView method besides being a UIViewController method.
to override it you need to subclass UIView or UITableView and not the controllers.
这是一个对我有用的 UITableView 子类解决方案。创建 UITableView 的子类并重写 hitTest:withEvent: ,如下所示:
Here is a UITableView subclass solution that worked for me. Make a subclass of UITableView and override hitTest:withEvent: as below:
TouchBegan 是 UIView 和 UITableViewCell 方法,而不是 UIViewController 和 UIViewController 方法。 UITableViewController 方法。
因此,您可以为 UITableViewCell 创建自定义类,它可以识别触摸事件和触摸委托,它正在为我工作。
祝你有美好的一天
touchesBegan is a UIView and UITableViewCell method rather than a UIViewController & UITableViewController method.
so you may create the the custom class for UITableViewCell it recognize the touch event and touch delegate it is working for me.
have a good day
IN SWIFT - 我在寻找 Swift 2 解决方案时遇到了这个问题。 @Steph Sharp 发布的答案帮助我解决了 Swift 中的问题,所以我将其发布在这里。给你:
功能
IN SWIFT - I came across this question while searching for a Swift 2 solution. The answer posted by @Steph Sharp helped me work out the the problem in Swift so I though I'de post it on here. Here you go:
Function