super respondsToSelector: returns true but actually calling super (selector) gives quot;unrecognized selector sent to instancequot;(super respondsToSelector:返回 true 但实际上调用 super (selector) 会给出“发送到实例的无法识别的选择器;)
问题描述
好吧,我有点困惑.
我有一个 UIScrollView 的子类,这是我尝试像 UI 元素一样水平滚动的表格视图".UIScrollView 本身设置了它在内部使用的 UIGestureRecognizers,并且它似乎将自己设置为那些 UIGestureRecognizers 的委托.我在我的水平表格元素/单元格上也有我自己的 UIGestureRecognizer 设置,我自己的类设置为我自己的 UIGestureRecognizer 的委托.由于我的类是 UIScrollView 的子类,因此在运行时,UIGestureRecognizer 委托调用会针对 UIScrollView 内置 UIGestureRecognizers 和我自己的 UIGestureRecognizers 进入我的类.有点像 PITA,但我们可以通过传递我们不关心的那些来解决这个问题.
I have a subclass of UIScrollView, which is my attempt at a horizontally scrolling "table view" like UI element. UIScrollView itself sets up UIGestureRecognizers it uses internally, and it appears to set itself up as the delegate for those UIGestureRecognizers. I also have my own UIGestureRecognizer setup on my horizontal table elements/cells and my own class set as delegate for my own UIGestureRecognizer. Since my class is a subclass of UIScrollView, at runtime, the UIGestureRecognizer delegate calls come to my class for both the UIScrollView in-built UIGestureRecognizers and my own UIGestureRecognizers. A bit of a PITA but we can work around this by passing on the ones we don't care about.
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]])
return NO;
else
{
if ([super respondsToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)])
return [super gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
else
return NO;
}
}
问题是检查 [super respondsToSelector:@selector()] 返回 YES,但是当我实际调用它时 return [super gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer]; 我得到以下异常
The problem is that the check [super respondsToSelector:@selector()] returns YES, but when I then actually call it return [super gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer]; I get the following exception
2012-08-31 12:02:06.156 MyApp[35875:707] -[MyAppHorizontalImageScroller gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]:无法识别的选择器发送到实例 0x21dd50
2012-08-31 12:02:06.156 MyApp[35875:707] -[MyAppHorizontalImageScroller gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: unrecognized selector sent to instance 0x21dd50
我以为它应该显示
-[UIScrollView 手势识别器:shouldRecognizeSimultaneouslyWithGestureRecognizer:]
-[UIScrollView gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]
但这可能没问题.但问题是它说它会响应然后没有响应.
But that may be OK. But the problem is that it says that it responds and then doesn't.
另外两个 UIGestureRecognizer 委托例程使用此代码(显然不同的选择器).
The other two UIGestureRecognizer delegate routines work with this code (different selectors obviously).
感谢您的任何见解.
推荐答案
除非您在类中覆盖响应选择器,否则您将在调用 super 时使用默认实现,该实现将检查当前实例.如果你想查看某类对象的实例是否响应选择器,请使用 +(BOOL)instancesRespondToSelector:(SEL)aSelector;
Unless you override responds to selector in your class you will be using the default implementation when you call super which will check the current instance. If you want to see if a instance of a type of object responds to a selector use +(BOOL)instancesRespondToSelector:(SEL)aSelector;
这将检查对象及其父对象.因此,在您的情况下,您需要以下内容:
This will check the object and its parent objects. So in your case you want to the following:
[UIScrollView instancesRespondToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)]
这篇关于super respondsToSelector:返回 true 但实际上调用 super (selector) 会给出“发送到实例的无法识别的选择器";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:super respondsToSelector:返回 true 但实际上调用 super (selector) 会给出“发送到实例的无法识别的选择器";
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
