开发者

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜