摘要: 协议(protocol)是Objective-c中一个非常重要的语言特性,从概念上讲,非常类似于JAVA中接口. 一个协议其实就是一系列有关联的方法的集合(为方便后面叙述,我们把这个协议命名为myProtocol)。协议中的方法并不是由协议本身去实现,相反而 是由遵循这个协议的其他类来实现。换句话说,协议myProtocol只是完成对协议函数的声明而并不管这些协议函数的具体实现。通常协议和delegate同时使用是一种非常好的设计模式。声明一个协议的语法非常简单:[cpp] view plaincopy@protocolmyProtocol@required-(void)protocolNam 阅读全文
posted @ 2013-09-09 17:47 如来藏 阅读(319) 评论(0) 推荐(0)
摘要: delegate很简单,就是将protocal方法声明好,然后将方法实现交由其delegate来实现,发送消息给delegate,delegate实现了protocal中的方法即在监听消息,就可以实现想要的操作了,多见于在不同view间传递数据。Becoming the Delegate of a Framework ClassA framework class or any other class that implements delegation declares a delegate property and a protocol (usually a formal protocol) 阅读全文
posted @ 2013-09-09 15:40 如来藏 阅读(525) 评论(0) 推荐(0)