how to set plot delegate in coreplot

2019-06-04 08:43发布

问题:

This is a follow up question from this link : coreplot bar tap not working and the answer is : Set the plot delegate to your bar plot delegate object. PLease can anybody tell me how .I am trying to create a simple bar-chart with on tap for 10 days and there is no tutorial which explains the process in simple words. It would be a great help and I would really appreciate it .Thanks in advance.

回答1:

You need to set your CPTBarPlot delegate. Until it is set, the CPTBarPlot object doesn't know where to send it's delegate method to.

In GraphView.m

Look for plot.dataSource = self and add the line plot.delegate = self (it's in the code where you are creating your CPTBarPlot *plot)

Then be sure to add the delegate method implementation to GraphView.m.

That should work, but it's worth pointing out that you should should not really be putting your dataSource and delegate methods in your view. This is a job for the view controller, as the controller mediates between the view and it's model, and directs user interaction. Similarly, your generateData method does not belong in the view, the data should be set / sent to the view via the view controller (I guess it's there just for testing purposes, but best to start as you mean to go on...).