为什么委托工作也没有在接口文件中定义它?(Why a delegate work also without defining it in the interface file?)

编程入门 行业动态 更新时间:2024-10-26 19:36:14
为什么委托工作也没有在接口文件中定义它?(Why a delegate work also without defining it in the interface file?)

我有一个简单的问题要问。

我有一个ViewController,它使用UITableView来显示事物列表。 UITableView委托是这个ViewController(使用dataSource = self等)。

在所有教程中,我知道我需要使用以下命令在接口中定义委托类:

@interface Class : SuperClass <ClassNameDelegate>

但是,所有代码都可以正常工作,而无需声明并仅实现方法。 例如:

@interface Class: SuperClass

是个bug吗? 我还是需要申报吗?

谢谢。

毛罗

I have a simple question to ask.

I have a ViewController that use a UITableView to show a list of things. The UITableView delegates are the this ViewController (using dataSource = self, etc..)

In all tutorials i know that i need to define the delegate class in the interface using:

@interface Class : SuperClass <ClassNameDelegate>

But all the code works good also without declaring this and implementing only the methods. For example:

@interface Class: SuperClass

Is a bug? I need to declare it anyways?

Thank you.

Mauro

最满意答案

在通常情况下,我们使用performSelector来调用委托方法,如下所示:

[(NSObject *)_delegate performSelector:@selector(storeFeedbackViewControllerWasDismissed)];

一切正常,因为这个委托有这个方法。

但最好指出该类符合协议,因为XCode可以警告您实现您可能错过的所需委托方法。

In common case we use performSelector to call delegate methods like this:

[(NSObject *)_delegate performSelector:@selector(storeFeedbackViewControllerWasDismissed)];

and everything works because this delegate have got this method.

But it's better to point that class conforms protocol because XCode can warn you to implement required delegate methods that you can miss.

更多推荐

本文发布于:2023-07-29 18:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1318676.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   定义   文件   工作   delegate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!