如何在Core Plot饼图中启用触摸select部分?

我正在使用Core Plot框架绘制饼图,并且在绘制饼图本身时没有问题。

然而,我需要饼图在本质上是交互式的,也就是说,如果我点击饼图中的任何特定部分,它应该触发导航到显示该特定部分的细节的页面。

我尝试使用方法-(void)pieChart:sliceWasSelectedAtRecordIndex:但委托方法从来没有被调用。 我需要什么来启用这种触摸互动?

我用CorePlot 0.2.2在iPad应用程序中实现了饼片select。 你的猜测使用(无效)pieChart:sliceWasSelectedAtRecordIndex:是正确的,但也许你已经忘记宣布以下两件事情:

  • 你的控制器是否声明了CPPieChartDelegate协议?
  • 你有没有告诉饼图你的控制器是它的代表

我的视图控制器在标题声明中看起来像这样:

 @interface YourViewController : UIViewController < CPPieChartDataSource, CPPieChartDelegate, ... > { ... CPXYGraph* pieGraph; CPGraphHostingView* pieView; } @property (nonatomic, retain) IBOutlet CPGraphHostingView* pieView; - (void)pieChart:(CPPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index; @end 

(void)viewDidLoad期间调用饼图的创build,在那里设置饼图的数据源和委托:

 -(void)viewDidLoad { [self createPie]; } -(void)createPie { pieGraph = [[CPXYGraph alloc] initWithFrame:CGRectZero]; pieGraph.axisSet = nil; self.pieView.hostedGraph = pieGraph; CPPieChart *pieChart = [[CPPieChart alloc] init]; // This is important in order to have your slice selection handler called! pieChart.delegate = self; pieChart.dataSource = self; pieChart.pieRadius = 80.0; [pieGraph addPlot:pieChart]; [pieChart release]; } - (void)pieChart:(CPPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index { // Do whatever you need when the pie slice has been selected. } 

使用最后的corePlot framework (1.4)我找不到CPPieChart但我用CPTPieChartDelegate

 @interface CPDFirstViewController : UIViewController <CPTPlotDataSource, CPTPieChartDelegate, ...> 

和这个方法:

 -(void)pieChart:(CPTPieChart *)pieChart sliceWasSelectedAtRecordIndex:(NSUInteger)index { // Put your action here } 

使用CorePlot 1.4CorePlot 1.4不再被认为是来自Xcode的Delegate

希望能帮助到你。

DOM