我正在尝试创建一个图形视图,该视图的末尾不断附加注释,以显示图形的值。它会随着滑块的移动而实时更新,随着图形值的变化,注释文本也会随之变化。
我把一些代码放在一起,让它工作得很好。然而,这涉及到按下横杆并用以下方式处理该按下:
- (void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)idx;这使我能够获得CPTBarPlot并对其进行检查。当图形加载时,我希望注释在那里,并无限期地保留在那里。因此,使用上述方法是不可行的。
这是我的numberForPlot方法,在其中我调用了一个我想要处理注释更新的方法。
-(NSNumber *)numberForPlot:(CPTPlot *)绘图字段:(NSUInteger)fieldEnum recordIndex:(NSUInteger)索引{
double ageNew = self.sliderOne.value - [self.budgetObject.larcNum doubleValue];
self.budgeObject = [self.budgetImpactFormula calculateBudgetImpactData:ageNew andOrganisation:self.organisationObject];
BudgetGraphObject *graphObject = [self getGraphScale];
if ((fieldEnum == CPTBarPlotFieldBarTip) && (index < 2)) {
if ([plot.identifier isEqual:@"UIPCurrent"]) {
return graphObject.uipCur;
}
else if ([plot.identifier isEqual:@"UIPProjected"]) {
[self addAnnotationToBar:plot value:[graphObject.uipProj doubleValue] atIndex:index];
return graphObject.uipProj;
}在这段代码中,我将我的方法称为addAnnotationToBar: value: atIndex:。然而,应用程序崩溃了,我意识到这是因为我传入的是CPTPlot而不是CPTBarPlot。应用程序崩溃的代码行是:[plot.graph.plotAreaFrame.plotArea addAnnotation:self.uipProjectedAnnotation];
经过进一步的研究,这里似乎是我处理注释更新的最佳位置。有没有什么办法可以让我从CPTPlot那里拿到CPTBarPlots?
我已经使用调试器找到了以下内容:

但是,我无法访问此数组。
任何关于如何在CPTPlot中获得CPTBarPlots的帮助都将不胜感激。
非常感谢。
发布于 2014-11-13 10:43:51
不要在数据源中这样做。设置图形时,将注释添加到绘图中。如果打印数据发生更改,可以在以后更新它们。
https://stackoverflow.com/questions/26898279
复制相似问题