简单易懂,实现代理方法
- viem.h 中声明
@protocol YQCourseHomeMallViewDelegate<NSObject>
@optional
- (void)mallView:(YQCourseHomeMallView *)mallView didClickItemAtIndex:(NSInteger)index;
@end
- viem.m 中触发
if (self.delegate && [self.delegate respondsToSelector:@selector(mallView:didClickItemAtIndex:)]) {
[self.delegate mallView:self didClickItemAtIndex:btn.tag - 1000];
}
- 调用View的地方.delegate = self;
- (YQCourseHomeMallView *)courseMallView {
if (!_courseMallView) {
_courseMallView = [[YQCourseHomeMallView alloc] initWithFrame:CGRectZero];
_courseMallView.delegate = self;
}
return _courseMallView;
}
- 重新实现代理方法。
#pragma mark -
#pragma mark YQCourseHomeMallViewDelegate
#pragma mark -
- (void)mallView:(YQCourseHomeMallView *)mallView didClickItemAtIndex:(NSInteger)index {
// do something
}
网友评论