我的代碼有效,但我不明白是誰或在哪裏爲我的視圖的數據源代理調用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