Iphone 在对象中调用方法会产生SIGBART

Iphone 在对象中调用方法会产生SIGBART,iphone,objective-c,ios,Iphone,Objective C,Ios,简单的问题,但这给了我一个错误,我似乎无法解决它 在我的对象(UIViewController)中,我在.h -(void)setCurrentLoc:(CLLocation *)loc; IBOutlet VectorViewController *vectorView; 在.m -(void)setCurrentLoc:(CLLocation *)loc { currentLocation = loc; } vectorView = [[VectorViewController

简单的问题,但这给了我一个错误,我似乎无法解决它

在我的对象(UIViewController)中,我在
.h

-(void)setCurrentLoc:(CLLocation *)loc;
IBOutlet VectorViewController *vectorView;
.m

-(void)setCurrentLoc:(CLLocation *)loc
{
    currentLocation = loc;
}
vectorView = [[VectorViewController alloc] init];
...
//In another method I call:
[vectorView setCurrentLoc:location]; // Error/SIGBART line
一切都好。但这就是我启动这个对象的方式(工作正常),但当我调用
setCurrentLoc:
时,它会给出SIGBART

.h

-(void)setCurrentLoc:(CLLocation *)loc;
IBOutlet VectorViewController *vectorView;
.m

-(void)setCurrentLoc:(CLLocation *)loc
{
    currentLocation = loc;
}
vectorView = [[VectorViewController alloc] init];
...
//In another method I call:
[vectorView setCurrentLoc:location]; // Error/SIGBART line
我错过了什么吗?也许不让它全球化或者什么的

错误:

-[UIView setCurrentLoc:]:发送到实例0x841cab0的选择器无法识别


根据您编写的代码,您不需要提供setCurrentLoc方法,而是使用属性,然后进行合成

在VectorViewController类中,使用:

@property (nonatomic, retain) IBOutlet CLLocation * currentLocation;
在@implementation中,添加:

@synthesize currentLocation;
在dealloc方法中,添加:

self.currentLocation = nil;
保持现有的setCurrentLocation调用不变

-[UIView setCurrentLoc:]:发送到实例0x841cab0的选择器无法识别

这意味着您将消息发送到的指针不再指向
VectorViewController
,而是指向
UIView
。这通常发生在对象被自动释放或释放,并且内存被重新使用时


仔细检查在创建vectorView和在其他方法中再次调用它之间发生的情况。您似乎是在直接设置和访问实例变量——您可能应该通过属性访问它(在不知道是否使用ARC的情况下很难具体),并确保正确声明这些属性

您是否声明并合成了当前位置?也许您应该使用self.currentLocation=loc;是的,我做了,但这并不是说,这给了错误。。。它在调用方法,我知道这一点。但事实并非如此。。。这是因为我在
vectorView
存在之前调用了它。这是因为它与在vectorView初始化之前发生的locationUpdate混合在一起,所以我将它放在locationUpdate中(使用if检查它是否已经存在)-现在可以正常工作。谢谢