这在objective-c中意味着什么:@interface SomeClass()<someotherclass> </someotherclass>

时间:2013-11-07 15:55:44

标签: objective-c

我开始在iOS开发世界中遇到一些不熟悉的东西。在我的MainViewController.m文件中,我有:

//import statements

@interface MainViewController() <CarouselViewDelegate>
//declaration of properties
@end

@implementation
//code
@end

MainViewController.h文件看起来像这样

@interface MainViewController : UIViewController
//code
@end

我感到困惑的是,这是做什么的(在一般意义上):@interface MainViewController() <CarouselViewDelegate>。看起来它使用泛型但不完全确定这里发生了什么。

感谢任何帮助,谢谢!

2 个答案:

答案 0 :(得分:2)

第一部分@interface MainViewController()class extension

它允许您以私有方式(而不是在头文件中)扩展类接口。它与Objective-C category是一样的,但是是匿名的。

第二位<CarouselViewDelegate>表示类扩展将符合CarouselViewDelegate protocol

所有协议都是一个接口,它定义了一个类可以(@optional)或必须(@required)采用的方法,以便在某个容量中为另一个类工作。在这种情况下,协议是一个名为CarouselView的类的delegate协议。

您必须查看特定协议文档或界面以查看其功能。您还必须将CarouselView的至少一个实例连接到MainViewController代理才能使其有用;通常这是使用IBOutlets在界面构建器中完成的,但可以通过编程方式完成,例如cv.delegate = mainVC

答案 1 :(得分:0)

这意味着您将实现名为CarouselViewDelegate

的委托

换句话说,CarouselViewDelegate是由另一个类(可能称为CarouselView)发布的一组方法,期望有人实现。在这种情况下,您的MainViewController会实施它们。

Java中的一种接口,但不一样。

更多信息:

Delegates and Datasources in iOS