CorePlot 在 iOS7 应用程序/Xcode5 中抛出异常

Posted

技术标签:

【中文标题】CorePlot 在 iOS7 应用程序/Xcode5 中抛出异常【英文标题】:CorePlot throws exceptions in iOS7 app / Xcode5 【发布时间】:2013-10-08 08:43:25 【问题描述】:

我有一个 ios7 应用程序,我正在尝试将 CorePlot 1.4 集成到(依赖项目安装)中。

@property (nonatomic) CPTGraphHostingView *hostingView;

_hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectNull];

_hostingView 会自动布局。)如果我再添加一个图表:

CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
_hostingView.hostedGraph = graph;

我首先得到这个异常:

-[CPTTextStyle attributes]: unrecognized selector sent to instance 0xa392900
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CPTTextStyle attributes]: unrecognized selector sent to instance 0xa392900'
5   myapp                     0x00074325 -[CPTAxis updateAxisLabelsAtLocations:inRange:useMajorAxisLabels:] + 1141
6   myapp                     0x00075662 -[CPTAxis relabel] + 1202

无奈之下,我通过以下方式在updateAxisLabelsAtLocations:inRange:useMajorAxisLabels 中修复了这个问题:

NSDictionary *textAttributes = nil;
BOOL hasAttributedFormatter  = FALSE;

然后得到下一个异常:

-[__NSCFString sizeWithTextStyle:]: unrecognized selector sent to instance 0x9591e90
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString sizeWithTextStyle:]: unrecognized selector sent to instance 0x9591e90'
5   myapp                     0x00081520 -[CPTTextLayer sizeThatFits] + 320
6   myapp                     0x0008163c -[CPTTextLayer sizeToFit] + 108
7   myapp                     0x00080559 -[CPTTextLayer initWithText:style:] + 313
8   myapp                     0x00074b87 -[CPTAxis updateAxisLabelsAtLocations:inRange:useMajorAxisLabels:] + 3159
9   myapp                     0x00075672 -[CPTAxis relabel] + 1202

然后我通过在sizeThatFits 中注释掉这一行来“修复”这个问题:

    else 
     //   textSize = [myText sizeWithTextStyle:self.textStyle];
    

下一个例外是:

-[__NSCFString drawInRect:withTextStyle:inContext:]: unrecognized selector sent to instance 0xa162bd0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString drawInRect:withTextStyle:inContext:]: unrecognized selector sent to instance 0xa162bd0'
5   myapp                     0x00081dc8 -[CPTTextLayer renderAsVectorInContext:] + 1144
6   myapp                     0x00063f60 -[CPTLayer drawInContext:] + 112

通过在renderAsVectorInContext中注释掉下面的代码来解决这个问题:

    else 
     //   [myText drawInRect:newBounds
     //        withTextStyle:self.textStyle
     //            inContext:context];
    

现在终于没有抛出异常并显示图形边框了。但是,如果我随后开始添加数据/图例等,则会引发新的异常:(

轴等上没有显示文本。当然这是因为我已经注释掉了代码。但是任何线索为什么会抛出这些异常?我很绝望;S

似乎我错过了集成中的一些基本内容。但是我的集成(虽然是 CorePlot 1.3)在 Xcode4 上的 iOS6 应用程序中运行良好。

【问题讨论】:

【参考方案1】:

检查您的应用项目中的链接器标志。核心情节需要-ObjC-all_load。有关详细信息,请参阅核心图 wiki。

【讨论】:

感谢 Eric - 真是如释重负!现在觉得自己很蠢 :) 有没有计划重构 CorePlot 以使用 ARC? 2.0 版本(已经在一个分支中)将放弃 GC 支持并使用 ARC。目前还没有发布时间表。

以上是关于CorePlot 在 iOS7 应用程序/Xcode5 中抛出异常的主要内容,如果未能解决你的问题,请参考以下文章

如何在 IOS 7 的 cordova 2.9.0 中删除状态栏?

如何防止xcode5切换到ios7布局

ios中的Coreplot构建失败问题

在 Mac OS X 上放大 CorePlot

CorePlot 中的缩放轴

使用 ZBar SDK 的 iPhone 应用程序的验证错误