Core Plot导致设备崩溃而不是模拟器

时间:2010-02-05 01:46:15

标签: iphone objective-c core-plot

我正在使用核心图在我的一个视图控制器中创建一个小图。我一直在试着追踪这个错误。我在模拟器上安装它工作正常,但一旦我把它放在我的设备上,我得到以下错误:

2010-02-04 22:15:37.394 Achieve[127:207] *** -[NSCFString drawAtPoint:withTextStyle:inContext:]: unrecognized selector sent to instance 0x108530
2010-02-04 22:15:37.411 Achieve[127:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString drawAtPoint:withTextStyle:inContext:]: unrecognized selector sent to instance 0x108530'
2010-02-04 22:15:37.427 Achieve[127:207] Stack: (
    843263261,
    825818644,
    843267069,
    842763033,
    842725440,
    253481,
    208187,
    823956912,
    823956516,
    823956336,
    823953488,
    823952500,
    823985628,
    842717233,
    843010887,
    843009055,
    860901832,
    843738160,
    843731504,
    8797,
    8692
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.

调试器输出(根据要求):

#0  0x33b3db2c in __kill
#1  0x33b3db20 in kill
#2  0x33b3db14 in raise
#3  0x33b54e3a in abort
#4  0x33c5c398 in __gnu_cxx::__verbose_terminate_handler
#5  0x313918a0 in _objc_terminate
#6  0x33c59a8c in __cxxabiv1::__terminate
#7  0x33c59b04 in std::terminate
#8  0x33c59c2c in __cxa_throw
#9  0x3138fe5c in objc_exception_throw
#10 0x32433bfc in -[NSObject doesNotRecognizeSelector:]
#11 0x323b8b18 in ___forwarding___
#12 0x323af840 in __forwarding_prep_0___
#13 0x0003de28 in -[CPTextLayer renderAsVectorInContext:] at
CPTextLayer.m:117
#14 0x00032d3a in -[CPLayer drawInContext:] at CPLayer.m:146
#15 0x311c95b0 in -[CALayer _display]
#16 0x311c9424 in -[CALayer display]
#17 0x311c9370 in CALayerDisplayIfNeeded
#18 0x311c8850 in CA::Context::commit_transaction
#19 0x311c8474 in CA::Transaction::commit
#20 0x311d05dc in CA::Transaction::observer_callback
#21 0x323ad830 in __CFRunLoopDoObservers
#22 0x323f5346 in CFRunLoopRunSpecific
#23 0x323f4c1e in CFRunLoopRunInMode
#24 0x335051c8 in GSEventRunModal
#25 0x324a6c30 in -[UIApplication _run]
#26 0x324a5230 in UIApplicationMain
#27 0x0000225c in main at main.m:14

这是我的viewDidLoad方法:

- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg.png"]];
    [self loadData];

    self.graph = [[CPXYGraph alloc] initWithFrame: self.plotView.frame];

    CPLayerHostingView *hostingView = self.plotView;
    hostingView.hostedLayer = graph;
    graph.paddingLeft = 50;
    graph.paddingTop = 10;
    graph.paddingRight = 10;
    graph.paddingBottom = 10;

    percentFormatter = [[NSNumberFormatter alloc] init];
    [percentFormatter setPercentSymbol:@"%"];
    [percentFormatter setNumberStyle:NSNumberFormatterPercentStyle];
    [percentFormatter setLocale: [NSLocale currentLocale]];
    [percentFormatter setMultiplier:[NSNumber numberWithInt:1]];
    [percentFormatter setMaximumFractionDigits:0];

    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
                                                   length:CPDecimalFromFloat(maxX)];
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minY) 
                                                   length:CPDecimalFromFloat(maxY-minY)];

    CPLineStyle *lineStyle = [[CPLineStyle lineStyle]retain];
    lineStyle.lineColor = [CPColor grayColor];
    lineStyle.lineWidth = 1.0f;

    CPTextStyle *whiteText = [CPTextStyle textStyle];
    whiteText.color = [CPColor whiteColor];    

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

    //  axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"0"]decimalValue];
    axisSet.xAxis.minorTicksPerInterval = 0;
    axisSet.xAxis.majorTickLineStyle = nil;
    axisSet.xAxis.minorTickLineStyle = nil;
    axisSet.xAxis.axisLineStyle = lineStyle;
    axisSet.xAxis.minorTickLength = 0;
    axisSet.xAxis.majorTickLength = 0;
    axisSet.xAxis.labelFormatter = nil;
    axisSet.xAxis.labelTextStyle = nil;

    axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:intY]decimalValue];
    axisSet.yAxis.minorTicksPerInterval = 5;
    axisSet.yAxis.majorTickLineStyle = lineStyle;
    axisSet.yAxis.minorTickLineStyle = lineStyle;
    axisSet.yAxis.axisLineStyle = lineStyle;
    axisSet.yAxis.minorTickLength = 2.0f;
    axisSet.yAxis.majorTickLength = 4.0f;
    axisSet.yAxis.labelFormatter = percentFormatter;
    axisSet.yAxis.labelTextStyle = whiteText;

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

}

任何帮助将不胜感激!

3 个答案:

答案 0 :(得分:3)

-drawAtPoint:withTextStyle:inContext:是在CPTextStyle.h中添加到NSString的类别方法。

为了使类别方法与iPhone上的Core Plot等静态库一起使用,您需要在项目的构建设置中将-ObjC添加到其他链接器标志中。在iPhone OS 3.0下,您可能还需要将-all_load添加到其他链接器标志中,以防止出现您所看到的异常。

instructions for using Core Plot within applications中记录了这一点。

答案 1 :(得分:1)

添加到项目framework/ iPhoneOnly源代码树中的CorePlot目录。

答案 2 :(得分:1)

我通过在Target> Settings中添加-all_load -ObjC标志使其工作正常。我认为这是每个人都感到困惑的地方。