编译使用核心剧情框架的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没有 '边界'。任何人都会遇到这种情况?
感谢您的信息,布拉德。我会在这里和你的建议一起去。我基本上从switchonthecode.com做了一个直接的复制/粘贴,并返回了这些错误。 方便的方法会很好,但如果我可以从图形对象中取出框架,可能不必要。 – 2009-10-21 14:15:29
不幸的是,框架上的API仍在不断发展,所以switchonthecode.com示例不再适用于当前版本的框架。需要做一些微小的调整才能使其与当前的API保持一致。对于那个很抱歉。 – 2009-10-21 15:21:18