模組平常都是用delegate去呼叫外部method來當作Callback使用,然而我們也可以利用delegate來作為DataSource去接外部資料回來使用。
//在.m中這樣呼叫你由外部輸入的Data
NSString *myKey = [self.dataSource getMyKey:self];
//在.h中這樣宣告
@protocol ReportChartDataSource;
@interface ReportChart : UIView
@property (weak, nonatomic) id<ReportChartDataSource> dataSource;
@property (nonatomic, readonly) ReportDuration duration;
- (void)reloadData;
- (void)reloadDataWithDuration:(ReportDuration)duration;
@end
//宣告實作
@protocol ReportChartDataSource <NSObject>
- (NSInteger) getMyKey:(ReportChart *)chart;
@end