拆分视图的 CorePlot 内部详细视图

发布于 2024-09-19 18:03:13 字数 3862 浏览 3 评论 0原文

我正在尝试将 CPXYGraph 加载到分割视图控制器的详细视图中。当它尝试显示绘图数据时,我收到 EXC_BAD_ACCESS。

我创建一个基于“基于拆分视图的应用程序”的新项目。添加 CorePlot 框架后,我进行了以下修改:

1- 添加 GraphController(.m、.h 和 .xib)。 xib 包含一个 UIView 和一个 CPLayerHostingView 类型的从属视图。 2- 将以下行添加到应用程序委托 didFinishLaunchingWithOptions

 [detailViewController performSelector:@selector(configureView) withObject:nil afterDelay:0];

3- 将以下行添加到 DetailViewController configureView

 CGRect graphFrame = CGRectMake(0, 43, 662, 450);
 GraphController *graphController = [[[GraphController alloc]
   initWithNibName:@"GraphController" bundle:nil] autorelease];
 [graphController.view setFrame:graphFrame];
 [self.view addSubview:graphController.view];
 [graphController reloadData];

4- GraphController 中的 reloadData 方法几乎是从 CorePlot 示例之一 (DatePlot) 粘贴的,我将复制并粘贴(大部分)它这里-

-(void)reloadData
{
    if (!graph)
    {
        [self parentViewController];
        [self.view addSubview:layerHost];

        // Create graph from theme
        graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
        CPTheme *theme = [CPTheme themeNamed:@"Dark Gradients"];
        [graph applyTheme:theme];
        ....
        [layerHost setHostedLayer: graph];
        ....
        // Setup scatter plot space
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        NSTimeInterval xLow = 0.0f;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLow) length:CPDecimalFromFloat(oneDay*5.0f)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.0) length:CPDecimalFromFloat(3.0)];

        // Axes
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
        CPXYAxis *x = axisSet.xAxis;
        x.majorIntervalLength = CPDecimalFromFloat(oneDay);
        x.orthogonalCoordinateDecimal = CPDecimalFromString(@"2");
        x.minorTicksPerInterval = 0;
        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        dateFormatter.dateStyle = kCFDateFormatterShortStyle;
        CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc] initWithDateFormatter:dateFormatter] autorelease];
        timeFormatter.referenceDate = refDate;
        x.labelFormatter = timeFormatter;

        CPXYAxis *y = axisSet.yAxis;
        y.majorIntervalLength = CPDecimalFromString(@"0.5");
        y.minorTicksPerInterval = 5;
        y.orthogonalCoordinateDecimal = CPDecimalFromFloat(oneDay);

        // Create a plot that uses the data source method
        CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease];
        dataSourceLinePlot.identifier = @"Date Plot";
        dataSourceLinePlot.dataLineStyle.lineWidth = 3.f;
        dataSourceLinePlot.dataLineStyle.lineColor = [CPColor greenColor];
        dataSourceLinePlot.dataSource = self;
        **[graph addPlot:dataSourceLinePlot];**

        // Add some data
        NSMutableArray *newData = [NSMutableArray array];
        NSUInteger i;
        for ( i = 0; i < 5; i++ ) {
            NSTimeInterval x = oneDay*i;
            id y = [NSDecimalNumber numberWithFloat:1.2*rand()/(float)RAND_MAX + 1.2];
            [newData addObject:
             [NSDictionary dictionaryWithObjectsAndKeys:
              [NSDecimalNumber numberWithFloat:x], [NSNumber numberWithInt:CPScatterPlotFieldX], 
              y, [NSNumber numberWithInt:CPScatterPlotFieldY], 
              nil]];
        }
        plotData = newData;
    }
}

有问题的行是 [graph addPlot:dataSourceLinePlot];如果我将其注释掉,模拟器就会出现并显示图表的 x 轴和 y 轴,当然没有数据。添加此行会导致以下 SIGART-

2010-09-15 14:35:58.959 SplitViewWithCorePlot[17301:207] relabel <<CPScatterPlot: 0x4c458c0> bounds: {{0, 0}, {558, 386}}>
Program received signal:  “EXC_BAD_ACCESS”.

有人可以帮忙吗?

I'm attempting to load a CPXYGraph into the detail view of a split view controller. I'm getting an EXC_BAD_ACCESS when it attempts to display the plot data.

I create a new project based on "Split View-based application". After adding the CorePlot framework I make the following modifications:

1- add a GraphController (.m, .h and .xib). The xib contains a UIView with a subordinate view of type CPLayerHostingView.
2- add the following line to the app delegate didFinishLaunchingWithOptions

 [detailViewController performSelector:@selector(configureView) withObject:nil afterDelay:0];

3- add the following to DetailViewController configureView

 CGRect graphFrame = CGRectMake(0, 43, 662, 450);
 GraphController *graphController = [[[GraphController alloc]
   initWithNibName:@"GraphController" bundle:nil] autorelease];
 [graphController.view setFrame:graphFrame];
 [self.view addSubview:graphController.view];
 [graphController reloadData];

4- the reloadData method in GraphController is pretty much pasted from one of the CorePlot samples (DatePlot) and I will copy and paste (most of) it here-

-(void)reloadData
{
    if (!graph)
    {
        [self parentViewController];
        [self.view addSubview:layerHost];

        // Create graph from theme
        graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
        CPTheme *theme = [CPTheme themeNamed:@"Dark Gradients"];
        [graph applyTheme:theme];
        ....
        [layerHost setHostedLayer: graph];
        ....
        // Setup scatter plot space
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        NSTimeInterval xLow = 0.0f;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLow) length:CPDecimalFromFloat(oneDay*5.0f)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.0) length:CPDecimalFromFloat(3.0)];

        // Axes
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
        CPXYAxis *x = axisSet.xAxis;
        x.majorIntervalLength = CPDecimalFromFloat(oneDay);
        x.orthogonalCoordinateDecimal = CPDecimalFromString(@"2");
        x.minorTicksPerInterval = 0;
        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        dateFormatter.dateStyle = kCFDateFormatterShortStyle;
        CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc] initWithDateFormatter:dateFormatter] autorelease];
        timeFormatter.referenceDate = refDate;
        x.labelFormatter = timeFormatter;

        CPXYAxis *y = axisSet.yAxis;
        y.majorIntervalLength = CPDecimalFromString(@"0.5");
        y.minorTicksPerInterval = 5;
        y.orthogonalCoordinateDecimal = CPDecimalFromFloat(oneDay);

        // Create a plot that uses the data source method
        CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease];
        dataSourceLinePlot.identifier = @"Date Plot";
        dataSourceLinePlot.dataLineStyle.lineWidth = 3.f;
        dataSourceLinePlot.dataLineStyle.lineColor = [CPColor greenColor];
        dataSourceLinePlot.dataSource = self;
        **[graph addPlot:dataSourceLinePlot];**

        // Add some data
        NSMutableArray *newData = [NSMutableArray array];
        NSUInteger i;
        for ( i = 0; i < 5; i++ ) {
            NSTimeInterval x = oneDay*i;
            id y = [NSDecimalNumber numberWithFloat:1.2*rand()/(float)RAND_MAX + 1.2];
            [newData addObject:
             [NSDictionary dictionaryWithObjectsAndKeys:
              [NSDecimalNumber numberWithFloat:x], [NSNumber numberWithInt:CPScatterPlotFieldX], 
              y, [NSNumber numberWithInt:CPScatterPlotFieldY], 
              nil]];
        }
        plotData = newData;
    }
}

The offending line is [graph addPlot:dataSourceLinePlot]; If I comment this out the simulator comes up and displays the x and y axis of the graph and of course no data. Adding this line back causes the following SIGART-

2010-09-15 14:35:58.959 SplitViewWithCorePlot[17301:207] relabel <<CPScatterPlot: 0x4c458c0> bounds: {{0, 0}, {558, 386}}>
Program received signal:  “EXC_BAD_ACCESS”.

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白况 2024-09-26 18:03:13

看起来您没有在任何地方保留数据数组。尝试将最后一条语句更改为

plotData = [newData retain];

or,如果您为其定义了属性,

self.plotData = newData;

Eric

It doesn't look like you're retaining the data array anywhere. Try changing the last statement to

plotData = [newData retain];

or, if you have a property defined for it,

self.plotData = newData;

Eric

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文