gpt4 book ai didi

iphone - 调用对象中的方法会给出 SIGBART

转载 作者:行者123 更新时间:2023-11-29 04:55:15 24 4
gpt4 key购买 nike

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

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

中声明了一个方法
-(void)setCurrentLoc:(CLLocation *)loc;

.m

-(void)setCurrentLoc:(CLLocation *)loc
{
currentLocation = loc;
}

一切都好。但这就是我启动这个对象的方式(工作正常),但是当我调用 setCurrentLoc: 时,它会给出 SIGBART

.h

IBOutlet VectorViewController *vectorView;

.m

vectorView = [[VectorViewController alloc] init];
...
//In another method I call:
[vectorView setCurrentLoc:location]; // Error/SIGBART line

是不是我漏掉了什么?也许不会使其全局化或其他什么?

错误:

-[UIView setCurrentLoc:]: unrecognized selector sent to instance 0x841cab0

最佳答案

-[UIView setCurrentLoc:]: unrecognized selector sent to instance 0x841cab0

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

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

关于iphone - 调用对象中的方法会给出 SIGBART,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8124843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com