objective-c - 在 iOS 设备之间发送数据时委托(delegate)响应选择器崩溃

标签 objective-c ios ios5

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

2012-06-21 10:22:15.509 BulletTime[2324:707] -[DataHandler selectorToCall:]: unrecognized selector sent to instance 0x19bfc0 2012-06-21 10:22:15.511 BulletTime[2324:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DataHandler selectorToCall:]: unrecognized selector sent to instance 0x19bfc0' * First throw call stack: (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) terminate called throwing an exception(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, info should be sent here. 2012-06-21 10:47:19.913 BulletTime[2416:707] BTM: attempting to connect to service 0x00000800 on device "Grace's iPad" A4:67:06:F3:EC:2A 2012-06-21 10:47:20.929 BulletTime[2416:707] BTM: connection to service 0x00000800 on device "Grace's iPad" A4:67:06:F3:EC:2A succeeded 2012-06-21 10:47:22.029 BulletTime[2416:707] -[DataHandler selectorToPerformWhenConnectionWasStablished:]: unrecognized selector sent to instance 0x1303f0 2012-06-21 10:47:22.032 BulletTime[2416:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DataHandler selectorToPerformWhenConnectionWasStablished:]: unrecognized selector sent to instance 0x1303f0' * First throw call stack: (0x356c188f 0x37a68259 0x356c4a9b 0x356c3915 0x3561e650 0x356207d3 0x6c693 0x351cf4ff 0x3568d547 0x35619097 0x351433eb 0x6ce1f 0x3069612f 0x356201fb 0x351e4747 0x35695ad3 0x3569529f 0x35694045 0x356174a5 0x3561736d 0x372b3439 0x33123cd5 0x6b2df 0x6b284) terminate called throwing an exception

最佳答案

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

也有同样的错误

关于objective-c - 在 iOS 设备之间发送数据时委托(delegate)响应选择器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11140386/

相关文章:

ios - 当 UIPopoverController 处于事件状态时,UIWebView 未检测到点击

iOS - NSXMLParser 和 libxml2 的区别

ios - 循环中所有值的延迟

ios - 代码 : Missing arm64 Symbols from MagTek iOS Library

ios - 具有可变单元格宽度和高度的 UICollectionViewFlowLayout 空白空间

ios - iOS 5 上的自动引用计数 (ARC)

objective-c - 如何使用 Objective-C 在 Mac OS X 上获取用户文件夹的位置

ios - 如何阻止我的细胞图像每次离开屏幕时都发生变化?

objective-c - UITextView 上的 UITableViewCell 选择

ios - 如何在 Swift 中向上滚动整个表格 View ?