什么是@interface UITableView(MyTableViewDelegate) [英] What is @interface UITableView (MyTableViewDelegate)

查看:147
本文介绍了什么是@interface UITableView(MyTableViewDelegate)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看其他人编写的一些源代码,我很想看到这一行:

Im looking at some source code written by someone else and its intrigues me to see this line:

@interface UITableView (MyTableViewGestureDelegate)

现在我以前只看过这个:

Now I have previously seen only this:

@interface MyTableView : UITableView <MyTableViewGestureDelegate>

所以我很困惑。

任何关于我在看什么的想法?

Any ideas as what to what im looking at?

Ben

推荐答案

这是一个类别声明。


一个类别允许你向现有类添加方法 - 甚至一个
你没有来源。类别是一个功能强大的
功能,允许您扩展现有
类的功能而无需子类化。使用类别,您还可以在几个文件中分发
您自己的类的实现。类
扩展类似,但允许在主类
@interface块以外的位置为类声明的额外必需API为

A category allows you to add methods to an existing class—even to one for which you do not have the source. Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing. Using categories, you can also distribute the implementation of your own classes among several files. Class extensions are similar, but allow additional required APIs to be declared for a class in locations other than within the primary class @interface block.

类别接口的声明看起来非常类似于类接口声明 - 除了类名称在类名称后面的括号中列出,并且未提及超类。除非其方法不访问该类的任何实例变量,否则该类别必须为其扩展的类导入接口文件:

The declaration of a category interface looks very much like a class interface declaration—except the category name is listed within parentheses after the class name and the superclass isn’t mentioned. Unless its methods don’t access any instance variables of the class, the category must import the interface file for the class it extends:

常规语法:

#import "ClassName.h"

@interface ClassName ( CategoryName )

// method declarations

@end

注意类别不能声明额外的类的实例变量;它只包括方法。但是,类范围内的所有实例变量也属于该类别的范围。这包括类声明的所有实例变量,甚至是声明为@private的实例变量。

Note that a category can’t declare additional instance variables for the class; it includes only methods. However, all instance variables within the scope of the class are also within the scope of the category. That includes all instance variables declared by the class, even ones declared @private.

您可以添加到类中的类别数量没有限制,但每个类别名称必须不同,每个名称都应声明并定义一组不同的方法。

There’s no limit to the number of categories that you can add to a class, but each category name must be different, and each should declare and define a different set of methods.

请检查 link 示例

这篇关于什么是@interface UITableView(MyTableViewDelegate)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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