My code works, but I don’t understand who or where is calling the setter for my view’s datasource delegate. I understand why calling that code makes everything work, I’d just like to know who makes the call / where it happens. The header for the view looks like this, with the last line of code being the important one:
@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
And the view controller that conforms to the protocol:
@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;
}
I have excluded the required protocol method and more, as its not relevant. What I want to know is who calls the above setGraphView method. Unfortunately, I couldn’t get help from a breakpoint (aside from knowing it was being called).
Also, that delegate first gets referenced by this code in the view:
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);
}
Is that where it happens???
The graphView and dataSource iVars are marked as IBOutlets, i.e. Interface Builder Outlet.
This would normally indicate that GraphViewController is loaded via a nib/xib file, and inside that nib file there are connections to these iVar from other objects inside the nib file.
So it is the nib loading mechanism that is calling the setters on those iVars.