Touches开始于UITableViewController [英] Touches began in UITableViewController

查看:114
本文介绍了Touches开始于UITableViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableViewController子类中定义此方法:

I am defining this method in my UITableViewController subclass:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    NSLog(@"touch began");
}

,但它没有被触发。 UIViewController是UIResponder的子类,所以它应该工作,对吧?
感谢

but it's not being triggered. UIViewController is a subclass of UIResponder so it should work, right? Thanks

推荐答案

是的,这绝对可以工作。

Yep, that should definitely work.

确保为此控制器对应的视图设置启用用户交互。

Make sure User Interaction Enabled is set for the view this controller corresponds to.

如果视图是从nib / xib加载的,请确保文件所有者设置为适当的类名,并且文件的所有者 / code> outlet连接到正确的视图。

If the view is loaded from a nib/xib, make sure File's Owner is set to be the appropriate class name, and File's Owner's view outlet is connected to proper the view.

更新:我也看到这种行为,使用基于Nav的应用程序模板构建的应用程序,但使用基于视图的应用程序模板,它按预期工作。

Update: I see this behavior as well, using an app built with the Nav-based App template, but with a View-based App template, it works as expected.

我认为在导航控制器的情况下,视图控制器中嵌入的表视图在视图控制器之前获取事件。请参见 UIView参考(强调

I think that in the case of a Navigation Controller, the table view embedded in the view controller is getting the event before the view controller does. See the UIView reference (emphasis mine):


视图控制器本身是UIResponder类

后代,并插入响应器
链在被管理的根视图
和它的superview之间,通常
属于一个不同的视图
控制器。 如果视图控制器的视图不处理事件
视图控制器本身具有处理事件的选项
,然后将事件传递到超级视图。

View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed root view and its superview, which typically belongs to a different view controller. If the view controller’s view does not handle an event, the view controller itself has the option of handling the event before passing the event along to the superview.

这意味着视图有第一次处理事件的机会,如果是这样,视图控制器将不会得到它。

This implies that the view has the first chance to handle the event, and if it does, the view controller won't get it.

不完全清楚你想要完成什么,所以我不知道提供什么解决方案。

Not exactly clear what you're trying to accomplish, so I'm not sure what solution to offer.

这篇关于Touches开始于UITableViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆