Iphone 错误:请求成员';界限';在非结构或联盟中

Iphone 错误:请求成员';界限';在非结构或联盟中,iphone,uiview,interface-builder,core-plot,Iphone,Uiview,Interface Builder,Core Plot,我在使用core plot框架编译iPhone应用程序时遇到上述错误。我将此视图控制器的视图链接到IB中的CPLayerHostingView。以下是viewDidLoad()函数的示例代码 - (void)viewDidLoad { [super viewDidLoad]; graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds]; CPLayerHostingView *hostingView = (C

我在使用core plot框架编译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没有“界限”。有人也遇到过这种情况吗?

尝试使用括号语法进行这些调用

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

作为图形的defaultPlotSpace返回的CPXYPlotSpace是CPPlotSpace的一个子类,它只是NSObject的一个子类。这些类都没有定义边界属性。相反,您可以通过CPPlotRange对象在CPXYPlotSpace中设置范围,如检索defaultPlotSpace后的前两行所示

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


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

此错误的问题通过添加Quartzcore框架(如果未包括)得到解决。

感谢您提供的信息,Brad。我同意你的建议。我基本上是直接从switchonthecode.com上复制/粘贴的,然后带着这些错误返回。方便的方法会很好,但如果我可以从graph对象获取框架,可能就没有必要了。不幸的是,框架上的API仍在不断发展,因此switchonthecode.com示例不再适用于框架的当前版本。需要进行一些轻微的调整,使其符合当前的API。很抱歉。