简体   繁体   English

在super上调用协议方法

[英]Calling protocol methods on super

Can I call a protocol method from a child on its super class, even though the super class supports the protocol privately? 我可以从超类的子进程调用协议方法,即使超类私有地支持协议吗?

Let's say I have a Class A which privately conforms to UIGestureRecognizerDelegate protocol. 假设我有一个私有符合UIGestureRecognizerDelegate协议的A类。 Class B inherits from Class A but when I tried to call [super gestureRecognizerShouldBegin:gestureRecognizer]; B类继承自A类,但当我试图调用[super gestureRecognizerShouldBegin:gestureRecognizer]时; I get an error. 我收到一个错误。

Any idea? 任何的想法?

The UIScrollViewDelegate doesn't declare a method named gestureRecognizerShouldBegin:gestureRecognizer: . UIScrollViewDelegate没有声明一个名为gestureRecognizerShouldBegin:gestureRecognizer:

But generally speaking, yes, its possible to call methods declared in protocols that the super class implements, but keep in mind that methods marked with @optional in the protocol aren't guaranteed to be implemented (you can check this via the respondsToSelector: method) 但一般来说,是的,它可以调用在超类实现的协议中声明的方法,但请记住,协议中标记为@optional方法不能保证实现(您可以通过respondsToSelector:方法检查这一点) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM