初学delegate,记录下,以防忘记
代理模式是一种消息传递方式,一个完整的代理模式包括:委托对象、代理对象和协议。
名词解释
协议:用来指定代理双方可以做什么,必须做什么。定义代理方法
委托对象:根据协议指定代理对象需要完成的事,即调用协议中的方法。制作代理
代理对象:根据协议实现委托方需要完成的事,即实现协议中的方法。实现代理
首先在需要代理的类的.h里边声明代理方法,
@property (nonatomic, weak) id<ScratVideoCellDelegate> delegate;
然后在.h的@interface之上定义代理方法
@protocol ScratVideoCellDelegate
- (void)cl_tableViewCellPlayVideoWithCell:(ScratVideoCell*)cell;
@end
然后在需要实现代理方法的类里边 调用代理ScratVideoCellDelegate
@interface RecommendedVC ()<UITableViewDataSource,UITableViewDelegate,ScratVideoCellDelegate>
然后实现代理方法(记得实例化的时候delegate = self)
-(void)cl_tableViewCellPlayVideoWithCell:(ScratVideoCell*)cell{
"传过来的值怎么用在这里边写就可以了"
}
网友评论