ladookie
ladookie

Reputation: 1371

Delegate not working

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

Upvotes: 0

Views: 818

Answers (1)

Tommy
Tommy

Reputation: 100622

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.

Upvotes: 3

Related Questions