我的代码有效,但我不明白是谁或在哪里为我的视图的数据源代理调用setter。我明白为什么调用该代码使一切正常工作,我只想知道是谁发出了呼叫/发生了什么。该视图的报头是这样的,用代码作为最后一行的重要之一:什么时候在iOS中调用委托设置器?
@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);
}
那是它发生在哪里???
谢谢,我想这可能是引擎盖下的东西,但我想确保我没有遗漏任何东西。 –
如果您想了解更多关于它的工作原理,请阅读资源编程指南。很高兴知道:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i-CH4-SW8 – bandejapaisa