views:

419

answers:

3

I'm using core plot to create a small plot in one of my view controllers. I have been pulling my hair out trying to track down this error. I install on the simulator and it works fine but as soon as I put it on my device I get the following error:

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”.

Debugger Output (as requested):

#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

Here is my viewDidLoad method:

- (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];

}

Any help would be appreciated!

+1  A: 

Add to you project the framework/ iPhoneOnly directory from the CorePlot source tree.

arul
I attempted that and got a bunch of errors on build. I then tried adding the relevant header files but that didn't solve the issue either.
Eric
It turns out I needed the CPTextStylePlatformSpecific.mfile and everything worked.
Eric
+3  A: 

-drawAtPoint:withTextStyle:inContext: is a category method added to NSString in CPTextStyle.h.

In order for category methods to be used with a static library like Core Plot on the iPhone, you will need to add -ObjC to your Other Linker Flags in your project's build settings. Under iPhone OS 3.0, you might also need to add -all_load to your Other Linker Flags to prevent exceptions like the one you're seeing.

This is documented in the instructions for using Core Plot within applications.

Brad Larson
I added the additional linker flag and it still didn't work. It looked promising because the issue is certainly related to the categories not being loaded. Thanks for sharing the link, I went through and made sure that I had done all of that correctly.
Eric
I recently upgraded to OS3.1.3 and the associated XCode version, I wonder if this could be an issue?
Eric
A: 

i got it working fine by adding the -all_load -ObjC flag in the Target>Settings. I think this is where everyone is getting confused.