尝试使用核心图进行编译时获取 EXC_BAD_ACCESS
作为 Objective C 和 xcode 的初学者,我正在尝试编写一个教程程序,可以在那里找到: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
我做了一些更改,所以它最终会编译,所以这是我的 .h (请原谅我的应用程序的愚蠢名称):
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface yutyyutViewController : UIViewController <CPTPlotDataSource>
{
CPTXYGraph *graph;
}
@end
这是我的 .m (至少是重要的部分):
#import "yutyyutViewController.h"
@implementation yutyyutViewController
- (void)viewDidLoad {
[super viewDidLoad];
CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
xSquaredtPlot.identifier = @"X Squared Plot";
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
xSquaredtPlot.dataLineStyle = dataLineStyle;
xSquaredtPlot.dataSource = self;
[graph addPlot:xSquaredtPlot];
在应用程序开始运行之后,我在最后三行的第一个非注释行处得到了 EXC_BAD_ACCESS 。
虽然我是初学者,但我花了很多时间研究这个问题,但在互联网上找不到解决方案。似乎我正在尝试访问 xSquaredtPlot,它是一个自动释放,这就是我收到错误的原因,但我理解的是,在我的 .h 中的属性中进行保留,并在我的 .m 中进行综合。但这并没有解决问题。
因此,我们将非常感谢任何帮助,如果我错过了答案,我很抱歉,尽管它已经在论坛上。
问候,克拉夫蒂。
As a beginner in objective C and xcode, I am trying to do a tutorial program that can be found there: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
I did some changes so it would finally compile, so here's my .h (please forgive the silly name of my application):
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface yutyyutViewController : UIViewController <CPTPlotDataSource>
{
CPTXYGraph *graph;
}
@end
And here's my .m (at least the important part):
#import "yutyyutViewController.h"
@implementation yutyyutViewController
- (void)viewDidLoad {
[super viewDidLoad];
CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
xSquaredtPlot.identifier = @"X Squared Plot";
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
xSquaredtPlot.dataLineStyle = dataLineStyle;
xSquaredtPlot.dataSource = self;
[graph addPlot:xSquaredtPlot];
And I get the EXC_BAD_ACCESS at the first non-commentary line of the three last lines, right after the application started running.
Although I am a beginner, I spent a lot of time looking into this and could not find the solution on internet. It seems like I'm trying to access xSquaredtPlot which is an autorelease and that is why I get the error, but what I understood is that doing a retain in a property in my .h, and a synthesize in my .m. BUt that didn't fix the problem.
So any help will be gladly appreciated and I'm sorry if I missed the answer although it's already on the forums.
Regards, Crafti.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是过时的教程。它已经推出两年多了,从那时起核心情节发生了很多变化。关键的一步是除了
-ObjC
之外,您还需要添加一个额外的链接器标志。您还需要添加-all_load
:我浏览了教程并更新了它可以与当前版本的 core-plot 一起使用。请注意,视图的类需要设置为
CPTGraphHostingView
而不是CPLayerHostingView
。这是我的工作版本:The problem is the outdated tutorial. It's over two years old and a lot has changed in core-plot since then. The crucial step is you need to add an additional linker flag besides
-ObjC
. You also need to add-all_load
:I went through the tutorial and updated it to work with the current version of core-plot. Note that the view's class needs to be set to
CPTGraphHostingView
notCPLayerHostingView
. Here is my working version: