【问题标题】:delegate method can not be called in singleton不能在单例中调用委托方法
【发布时间】:2014-02-10 08:36:41
【问题描述】:
static LocationClass * locationClass= nil;
loationManger.delegate = locationClass;
[loationManger startUpdatingLocation];

-locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

.h 我得到了 CLLocationManagerDelegate。这是一个单例类,但是方法 fullface 不能被调用,有人可以帮助我吗?

【问题讨论】:

  • “但是方法fullface不能被调用”是什么意思?当您调用loationManger.delegate = locationClass; 时,locationClass 是真的指向一个对象还是仍然是nil
  • 无法调用委托方法...在获取方法之前,我已经获取了shareclass方法;
  • 这并不能回答我的问题。当我们试图帮助您并询问有关您的设置的问题时,请尝试提供更多信息。调用loationManger.delegate = locationClass;时,请使用调试器或NSLog验证locationClass不是nil
  • 我已经修好了。谢谢!!

标签: ios methods singleton


【解决方案1】:

你没有通过static LocationClass * locationClass= nil; 分配内存 这就是为什么没有调用您的代表的原因。必须分配委托才能使用。

试试

static LocationClass * locationClass= [[LocationClass alloc]init];

它将分配内存并调用您的委托方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多