我的代码有效,但我不明白谁或在哪里为我的视图的数据源委托调用 setter。我理解为什么调用该代码会使一切正常,我只想知道是谁进行了调用/它发生在哪里。视图的标题如下所示,最后一行代码很重要:
@class GraphView;
@protocol GraphViewDataSource
-(float)YValueforXValue:(float)xValue;
@end
@interface GraphView : UIView
@property (nonatomic) CGFloat scale;
@property (nonatomic) CGPoint graphOrigin;
@property (nonatomic, weak) IBOutlet id <GraphViewDataSource> dataSource;
@end
以及符合协议的视图控制器:
@interface GraphViewController () <GraphViewDataSource>
@property (nonatomic, weak) IBOutlet GraphView *graphview;
@end
@implementation GraphViewController
@synthesize graphview = _graphview;
@synthesize program = _program;
-(void)setGraphview:(GraphView *)graphview {
_graphview = graphview;
self.graphview.dataSource = self;
}
我已经排除了所需的协议方法等,因为它不相关。我想知道是谁调用了上述setGraphView
方法。不幸的是,我无法从断点获得帮助(除了知道它正在被调用)。
此外,该委托首先被视图中的此代码引用:
for (CGFloat thisPointViewXValue=self.bounds.origin.x; thisPointViewXValue<=self.bounds.size.width; thisPointViewXValue +=1/self.contentScaleFactor)
{
if (FirstPoint) {
CGFloat firstpointGraphXValue = [self convertViewXValueToGraphXValue:thisPointViewXValue];
CGFloat firstpointGraphYValue = [self.dataSource YValueforXValue:firstpointGraphXValue];
CGFloat firstpointViewYValue = [self convertGraphYValueToViewY:firstpointGraphYValue];
CGContextMoveToPoint(context, thisPointViewXValue, firstpointViewYValue);
FirstPoint = NO;
}
CGFloat thisPointGraphXValue = [self convertViewXValueToGraphXValue:thisPointViewXValue];
CGFloat thisPointGraphYValue = [self.dataSource YValueforXValue:thisPointGraphXValue];
CGFloat thisPointViewYValue = [self convertGraphYValueToViewY:thisPointGraphYValue];
CGContextAddLineToPoint(context, thisPointViewXValue, thisPointViewYValue);
}
这是发生的地方吗???