I have this code in my viewController:
- (GraphModel *)graphModel
{
if (!graphModel) {
graphModel = [[GraphModel alloc] init];
NSLog(@"graphModel = %@", graphModel);
}
return graphModel;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.graphView.delegate = [self graphModel];
NSLog(@"self.graphview.delegate = %@", self.graphView开发者_运维问答.delegate);
[self updateUI];
}
but the NSLog just says (null) for self.graphview.delegate even though the NSLog in graphModel says that I successfully created an object. How can this be?
this is the code for the graphViewDelegate
@class GraphView;
@protocol GraphViewDelegate
- (double)yValueForGraphView:(GraphView *)requestor atPosition:(int)i withPrecision:(int)precision;
- (double)scaleForGraphView:(GraphView *)requestor;
@end
@interface GraphView : UIView {
id <GraphViewDelegate> delegate;
}
@property (assign) id <GraphViewDelegate> delegate;
@end
and then I have @synthesize delegate
in graphView.m
Most likely guess: graphView is nil. Calling any method on a nil object has no effect and returns nil, and the .delegate is actually a call to the getter or setter as appropriate. I recommend you add:
NSLog(@"self.graphview = %@", self.graphView);
As a quick verification.
精彩评论