我正在使用 Core Plot 框架来绘制饼图,并且在绘制饼图本身时没有任何问题。
但是,我需要饼图本质上是交互式的,即,如果我点击饼图中的任何特定部分,它应该触发导航到显示该特定部分的详细信息的页面。
我尝试使用该方法-(void)pieChart:sliceWasSelectedAtRecordIndex:
,但该委托方法从未被调用。我需要什么才能启用这种触摸交互?
我已经使用 CorePlot 0.2.2 在我的 iPad 应用程序中实现了饼图选择。你的猜测使用(void)pieChart:sliceWasSelectedAtRecordIndex:是正确的,但也许你已经忘记了
声明以下两件事:
- 您的控制器是否声明了CPP饼图委托协议?
- 你有没有告诉饼图你的控制器是它的delegate?
我的视图控制器在标头声明中如下所示:
@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.
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)