【发布时间】:2010-12-22 05:50:40
【问题描述】:
我正在使用 Core Plot 框架来绘制饼图,并且在绘制饼图本身时没有任何问题。
但是,我需要饼图本质上是交互式的,即,如果我点击饼图中的任何特定部分,它应该会触发导航到显示该特定部分详细信息的页面。
我尝试使用方法-(void)pieChart:sliceWasSelectedAtRecordIndex:,但从未调用过该委托方法。我需要什么才能启用这种触摸交互?
【问题讨论】:
我正在使用 Core Plot 框架来绘制饼图,并且在绘制饼图本身时没有任何问题。
但是,我需要饼图本质上是交互式的,即,如果我点击饼图中的任何特定部分,它应该会触发导航到显示该特定部分详细信息的页面。
我尝试使用方法-(void)pieChart:sliceWasSelectedAtRecordIndex:,但从未调用过该委托方法。我需要什么才能启用这种触摸交互?
【问题讨论】:
我已经在我的 iPad 应用中使用 CorePlot 0.2.2 实现了饼图选择。你的猜测使用 (void)pieChart:sliceWasSelectedAtRecordIndex: 是正确的,但也许你忘记了 声明以下两件事:
我的视图控制器在标头声明中如下所示:
@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期间调用的,这里我设置了饼图的数据源和委托:
-(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
}
CPPieChartDelegate 不再被识别为 Xcode 中的委托,使用 CorePlot 1.4
希望对你有帮助。
dom
【讨论】: