0

您好已使用核心绘图框架http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application遵循本教程

我的项目编译,但在尝试视图时崩溃。我想我与 UIView / 故事板有关。尽管我已经将 UIView 中的类更改为CPTGraphHostingView我仍然收到以下错误

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIView setHostedGraph:]: unrecognized selector sent to instance 0x6b8afe0”

有任何想法吗 ?下面的代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //CPTGraphHostingView *hostingView = (CPTGraphHostingView *) self.view;
    //CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
    //[self.view addSubview:hostingView];
    hostingView.hostedGraph = graph;

    graph.plotAreaFrame.plotArea.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];


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

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-6) 
                                                    length:CPTDecimalFromFloat(12)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-5) 
                                                    length:CPTDecimalFromFloat(30)];

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;

    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineColor = [CPTColor blackColor];
    lineStyle.lineWidth = 2.0f;

    axisSet.xAxis.majorIntervalLength = [[NSNumber numberWithInt: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.labelOffset = 3.0f;

    axisSet.yAxis.majorIntervalLength = [[NSNumber numberWithInt: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.labelOffset = 3.0f;

    CPTScatterPlot *xSquaredPlot = [[CPTScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.accessibilityFrame];
    xSquaredPlot.identifier = @"X Squared Plot";
    CPTMutableLineStyle *ls1 = [CPTMutableLineStyle lineStyle];
    ls1.lineWidth = 1.0f;
    ls1.lineColor = [CPTColor redColor];
    xSquaredPlot.dataLineStyle = ls1;
    xSquaredPlot.dataSource = self;
    [graph addPlot:xSquaredPlot];

    CPTPlotSymbol *greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor greenColor]];
    greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
    xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  

    CPTScatterPlot *xInversePlot = [[CPTScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.accessibilityFrame];

    xInversePlot.identifier = @"X Inverse Plot";
    CPTMutableLineStyle *ls2 = [CPTMutableLineStyle lineStyle];
    ls2.lineWidth = 1.0f;
    ls2.lineColor = [CPTColor blueColor];
    xInversePlot.dataLineStyle = ls2;
    xInversePlot.dataSource = self;
    [graph addPlot:xInversePlot];
}
4

1 回答 1

0

我在编译器选项中添加了 -Load_All 和 -ObjC,然后似乎没问题 :-)

于 2012-06-26T14:12:17.497 回答