title: Core Plot DataSource delegate methods implemented in separate Object are not called
body: <p>I have two classes, GraphViewController and AppController. AppController (the delegate) implements the datasource protocol of GraphViewController. The problem I have is that those methods are not called by GraphViewController. </p>
  
  <p>However, when I set the datasource of GraphViewController to self and leave the protocol methods in the GraphViewController (like in the CorePlot example provided with CorePlot) everything works fine without any reloadData or setNeedsDisplay methods called.  </p>
  
  <p>The problem is not the setup of the view. The theme and the axis are drawn fine, just the plot is missing.</p>
  
  <p>None of the provided answers to very similar questions solved my particular problem. I guess (or hope) that it's just a small thing I'm missing, but I just can't find it.</p>
  
  <p>See the source of the two classes below. Oh, and by the way: this is for OS-X not iOS.</p>
  
  <p>GraphViewController.h:</p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  #import &lt;CorePlot/CorePlot.h&gt;
  
  @interface GraphViewController : NSObject{
  
      IBOutlet CPTGraphHostingView *graphHostingViewOutlet;
      CPTXYGraph *graph;
  }
  
  @property (weak) id&lt;CPTPlotDataSource&gt; delegate;
  
  @end
  </code></pre>
  
  <p>GraphViewController.m:</p>
  
  <pre><code>#import "GraphViewController.h"
  
  @implementation GraphViewController
  
  @synthesize delegate;
  
  -(void)awakeFromNib {
  
      [super awakeFromNib];
  
      // create graph
      graph = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:CGRectZero];
  
      // apply theme to graph
      [graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
  
      // connect graph to host view
      graphHostingViewOutlet.hostedGraph = graph;
  
      // get a pointer to the default plot space of the graph
      CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
  
      // setup axes limits
      plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-0.2f) length:CPTDecimalFromFloat(1.2f)];
      plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-0.2f) length:CPTDecimalFromFloat(1.2f)];
  
      // get a pointer to the axis set of the graph
      CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
  
      // get the x axis element of the axis set and set propertys for x axis
      CPTXYAxis *x = axisSet.xAxis;
      x.majorIntervalLength = CPTDecimalFromFloat(0.2f);
  
      // get the y axis element of the axis set and set propertys for y axis
      CPTXYAxis *y = axisSet.yAxis;
      y.majorIntervalLength = CPTDecimalFromFloat(0.2f);
  
      // create a new plot
      CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init];
  
      // set the identifier for the plot
      dataSourceLinePlot.identifier = @"ThePlot";
  
      // set data source for plot
      dataSourceLinePlot.dataSource = delegate;
  
      // add the plot to the graph
      [graph addPlot:dataSourceLinePlot];
  
  }
  
  @end
  </code></pre>
  
  <p>AppController.h:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import "GraphViewController.h"
  #import &lt;CorePlot/CorePlot.h&gt;
  
  @interface AppController : NSObject &lt;CPTPlotDataSource&gt;
  
  @property (weak) GraphViewController *graphViewController;
  
  - (IBAction)doSomething:(id)sender; // connected to a button
  
  @end
  </code></pre>
  
  <p>AppController.m:</p>
  
  <pre><code>#import "AppController.h"
  
  @implementation AppController{
  
      NSArray *_plotData;
  
  }
  
  @synthesize graphViewController = _graphViewController;
  
  -(void)awakeFromNib {
  
      [super awakeFromNib];
  
      [_graphViewController setDelegate:self];
  
      // create data array
      NSMutableArray *newData = [NSMutableArray array];
  
      for (NSUInteger i = 0; i &lt; 20; i++ ) {
  
          // create random y values
          id y = [NSDecimalNumber numberWithFloat: rand() / (float)RAND_MAX];
  
          [newData addObject: [NSDictionary dictionaryWithObjectsAndKeys:
  
                               [NSDecimalNumber  numberWithFloat:0.05 * i],      // x object
                               [NSNumber numberWithInt:CPTScatterPlotFieldX],    // key
                               y,                                                // y object
                               [NSNumber numberWithInt:CPTScatterPlotFieldY],    // key
                               nil]];
      } // end of for
  
      _plotData = newData;
  }
  
  - (IBAction)doSomething:(id)sender{ // connected to a working button
  
      NSLog(@"Button was pressed.");
  
      // tell the graphViewController to reload its data from its delegate (me), but how?
  
      // this does not work: [[NSNotificationCenter defaultCenter] postNotificationName:@"CPTGraphNeedsRedrawNotification" object:nil];
  
  }
  
  // implementation of delegate methods
  
  -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
  {
      NSDecimalNumber *num = [[_plotData objectAtIndex:index] objectForKey:[NSNumber numberWithLongLong:fieldEnum]];
      NSLog(@"numberForPlot was called, num is %@",num);
      return num;
  }
  
  -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
  {
      NSLog(@"numberForPlot was called.");
      return _plotData.count;
  }
  
  @end
  </code></pre>
  
  <p>I hope the source I posted can serve as a simple prototype for others once the bug was found.</p>