【问题标题】:Delegate responding to selector crash when Sending Data between iOS Devices在 iOS 设备之间发送数据时委托响应选择器崩溃
【发布时间】:2012-06-21 23:30:19
【问题描述】:

从一台 iOS 设备向另一台设备发送数据时,我收到这些错误。

2012-06-21 10:22:15.509 BulletTime[2324:707] -[DataHandler selectorToCall:]:无法识别的选择器发送到实例 0x19bfc0 2012-06-21 10:22:15.511 BulletTime[2324:707] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[DataHandler selectorToCall:]:无法识别的选择器发送到实例 0x19bfc0” * 首先抛出调用栈: (0x356c188f 0x37a68259 0x356c4a9b 0x356c3915 0x3561e650 0x356207d3 0xb6fd1 0xb7121 0x3322f61b 0x3561b3fd 0x33110e07 0x33110dc3 0x33110da1 0x33110b11 0x33111449 0x3310f92b 0x3310f319 0x330f5695 0x330f4f3b 0x372b422b 0x35695523 0x356954c5 0x35694313 0x356174a5 0x3561736d 0x372b3439 0x33123cd5 0xb231f 0xb22c4) 终止称为抛出异常(lldb)

我确定是这段代码导致了崩溃,但我不知道如何修复它:

- (void)sendInfo {
    //Attempting to send info to the other device.
    //Returns to the Data Handler.
    info = (BOOL*)YES;

    //Sets the requestLabel and requestData of the CameraRequestDataProvider object.
    //These are then handled in the DataHandler...
    requestLabel = @"Cam";
    requestData = [@"Cam" dataUsingEncoding:NSUTF8StringEncoding];

    //Crash occurs here...

    if (delegateToCall && [delegateToCall respondsToSelector:selectorToCall])

        [delegateToCall performSelector:@selector(selectorToCall:)];
}

过去几天我一直在尝试解决这个问题,但没有运气。有任何想法吗?我将不胜感激!

知道了!谢谢,我修正了这个错误。

但是,现在我收到了这个错误:

2012-06-21 10:47:16.779 BulletTime[2416:707] ButtonIndex 0,信息应该在这里发送。 2012-06-21 10:47:19.913 BulletTime [2416:707] BTM:尝试连接到设备“Grace 的 iPad”A4:67:06:F3:EC:2A 上的服务 0x00000800 2012-06-21 10:47:20.929 BulletTime [2416:707] BTM:连接到设备“Grace 的 iPad”A4:67:06:F3:EC:2A 上的服务 0x00000800 成功 2012-06-21 10:47:22.029 BulletTime[2416:707]-[DataHandler selectorToPerformWhenConnectionWasStablished:]:无法识别的选择器发送到实例 0x1303f0 2012-06-21 10:47:22.032 BulletTime[2416:707] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[DataHandler selectorToPerformWhenConnectionWasStablished:]:无法识别的选择器发送到实例 0x1303f0” * 首先抛出调用栈: (0x356c188f 0x37a68259 0x356c4a9b 0x356c3915 0x3561e650 0x356207d3 0x6c693 0x351cf4ff 0x3568d547 0x35619097 0x351433eb 0x6ce1f 0x3069612f 0x356201fb 0x351e4747 0x35695ad3 0x3569529f 0x35694045 0x356174a5 0x3561736d 0x372b3439 0x33123cd5 0x6b2df 0x6b284) 终止称为抛出异常

【问题讨论】:

  • 请原谅我的无知,但是 DataHandler 类是什么?是否有方法 selectorToCall:?
  • 据我所知,selectorToCallselectorToCall: 是两个不同的消息。向我们展示 delegateToCall 类代码。
  • 你的“selectorToCall:”声明和代码是什么样的?
  • 好的,我的所有课程都可以在这里找到:github.com/Glchriste/BulletTime
  • 我没有看到DataHandler,这是一个有趣的,因为它的名字出现在错误中。 (sendInfo 方法在哪个类?)

标签: objective-c ios ios5


【解决方案1】:
if (delegateToCall && [delegateToCall respondsToSelector:selectorToCall])

    [delegateToCall performSelector:selectorToCall];

同样的方法错误

- (void)cancelInfo:(id)sender {
    [mainViewController dismissModalViewControllerAnimated:NO];
    [delegateToCall performSelector:@selector(selectorToCall:)];    
}

需要替换为

- (void)cancelInfo:(id)sender {
    [mainViewController dismissModalViewControllerAnimated:NO];
    [delegateToCall performSelector:selectorToCall];    
}

更新:

在 Device.m 文件中的方法相同的错误:

- (void)triggerConnectionSuccessfull:(NSNotification *)notification

替换字符串

[delegateToCallAboutConnection performSelector:@selector(selectorToPerformWhenConnectionWasStablished:)];

到字符串

[delegateToCallAboutConnection performSelector:selectorToPerformWhenConnectionWasStablished];

和方法

- (void)triggerConnectionFailed:(NSNotification *)notification

也有同样的错误

【讨论】:

    【解决方案2】:

    您正在 github 源代码中 CameraDataProvider 的第 105 行或第 110 行设置成员变量 selectorToCall。这意味着您不需要在 performSelector 调用结束时使用冒号。

    而不是寻找在 selectorToCall 中设置的选择器,

     [delegateToCall performSelector:@selector(selectorToCall:)];
    

    正在 DataHandler 上寻找一个名称为 selectorToCall 的方法,该方法采用一个参数(因为冒号)。

    【讨论】:

    • 谢谢!我通过删除@selector 和分号修复了该错误。但是,现在我收到一个新错误(在顶部更新)。我会努力弄清楚的。
    • 好的,两个都修好了。现在我只需要处理我的 DataHandler 抛出的意外命令错误异常,这应该不太难修复(希望如此)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多