2009-10-19 64 views
0

编译使用核心剧情框架的iPhone应用程序时出现上述错误。我将此视图控制器的视图链接到IB中的CPLayerHostingView。以下是viewDidLoad()函数的示例代码。错误:请求成员的'边界'在某些不是结构或工会

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds]; 

    CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view; 
    hostingView.hostedLayer = graph; 


    graph.paddingLeft = 20.0; 
    graph.paddingTop = 20.0; 
    graph.paddingRight = 20.0; 
    graph.paddingBottom = 20.0; 


    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6) 
                length:CPDecimalFromFloat(12)]; 
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5) 
                length:CPDecimalFromFloat(30)]; 

    CPLineStyle *lineStyle = [CPLineStyle lineStyle]; 
    lineStyle.lineColor = [CPColor blackColor]; 
    lineStyle.lineWidth = 2.0f; 

    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; 
    axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue]; 
    axisSet.xAxis.minorTicksPerInterval = 4; 
    axisSet.xAxis.majorTickLineStyle = lineStyle; 
    axisSet.xAxis.minorTickLineStyle = lineStyle; 
    axisSet.xAxis.axisLineStyle = lineStyle; 
    axisSet.xAxis.minorTickLength = 5.0f; 
    axisSet.xAxis.majorTickLength = 7.0f; 
    axisSet.xAxis.axisLabelOffset = 3.0f; 

    axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue]; 
    axisSet.yAxis.minorTicksPerInterval = 4; 
    axisSet.yAxis.majorTickLineStyle = lineStyle; 
    axisSet.yAxis.minorTickLineStyle = lineStyle; 
    axisSet.yAxis.axisLineStyle = lineStyle; 
    axisSet.yAxis.minorTickLength = 5.0f; 
    axisSet.yAxis.majorTickLength = 7.0f; 
    axisSet.yAxis.axisLabelOffset = 3.0f; 

    CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 
    xSquaredPlot.identifier = @"X Squared Plot"; 
    xSquaredPlot.dataLineStyle.lineWidth = 1.0f; 
    xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor]; 
    xSquaredPlot.dataSource = self; 
    [graph addPlot:xSquaredPlot]; 

    CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol]; 
    greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]]; 
    greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0); 

    [xSquaredPlot setPlotSymbol:greenCirclePlotSymbol]; 

    CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 
    xInversePlot.identifier = @"X Inverse Plot"; 
    xInversePlot.dataLineStyle.lineWidth = 1.0f; 
    xInversePlot.dataLineStyle.lineColor = [CPColor blueColor]; 
    xInversePlot.dataSource = self; 
    [graph addPlot:xInversePlot]; 
} 

麻烦的线是这些:

CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 

它说有从graph.defaultPlotSpace没有 '边界'。任何人都会遇到这种情况?

回答

1

使用括号语法尝试这些调用。

CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:[[graph defaultPlotSpace] bounds]] autorelease]; 
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:[[graph defaultPlotSpace] bounds]] autorelease]; 
1

你找回作为图形的defaultPlotSpace的CPXYPlotSpace是CPPlotSpace,这仅仅是一个NSObject的子类的子类。这些类都没有定义边界属性。相反,CPXYPlotSpace可以通过CPPlotRange对象设置范围,正如您在检索defaultPlotSpace后的前两行中看到的那样。

做你想做的事的正确方法是分配图,只使用-init,而不是-initWithFrame :.当这些图被添加到图中时,我相信它们会根据绘图空间自动调整大小。或者,您可以使用-initWithFrame:并使用图形的框架。

如果您想查看返回CPXYPlotSpace边界的便捷方法,请在mailing list中告诉我们。

+0

感谢您的信息,布拉德。我会在这里和你的建议一起去。我基本上从switchonthecode.com做了一个直接的复制/粘贴,并返回了这些错误。 方便的方法会很好,但如果我可以从图形对象中取出框架,可能不必要。 – 2009-10-21 14:15:29

+0

不幸的是,框架上的API仍在不断发展,所以switchonthecode.com示例不再适用于当前版本的框架。需要做一些微小的调整才能使其与当前的API保持一致。对于那个很抱歉。 – 2009-10-21 15:21:18

0

这个错误的问题是通过添加Quartzcore框架来解决的,如果它没有包含的话。