我是核心情节框架的新手,面临一个问题:
我是CPGraphHostigView绘制饼图。由于CPGraphHostigView
未检测到触摸事件,因此我可以检测到触摸事件UIView
。现在,我如何将此触摸事件传递给饼图,以便CPPieChartDelegate
方法。
- (void)pieChart:(CPPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index
被调用。
感谢任何帮助。提前谢谢。
-Ravi
答案 0 :(得分:1)
CPGraphHostingView
继承自UIView
,继承自UIResponder
。因此,CPGraphHostingView
会检测到触摸事件。
为了检测饼图切片上的触摸事件,您应遵循以下步骤:
CPGraphHostingView
。您可以通过添加简单的UIView
并手动将其类更改为CPGraphHostingView
; 在代码中声明您的托管视图:
// In your view controller .h file:
...
CPGraphHostingView *graphHosting;
}
@property (nonatomic, retain) IBOutlet CPGraphHostingView *graphHosting;
// In your view controller .h file:
@synthesize graphHosting;
在Interface Builder中与IBOutlet建立连接;
初始化图表并将其链接到图表托管视图:
self.graph = [[CPXYGraph alloc] initWithFrame: self.graphHosting.bounds];
self.graphHosting.hostedGraph = self.graph;
初始化饼图并将视图控制器设置为其委托:
CPPieChart *pieChart = [[CPPieChart alloc] init];
pieChart.delegate = self;
...
[self.graph addPlot:pieChart]
[pieChart release];
将<CPPieChartDelegate>
添加到视图控制器的声明中,并实现方法:
- (void)pieChart:(CPPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index