invokeSelector:withObject:在发布中崩溃

时间:2012-11-20 17:56:41

标签: objective-c ios

我有代码

[target invokeSelector:handler.successAction withObject:object];

它可能会调用一些方法。有对象或没有对象。它完全适用于Debug,但在Release:

中崩溃
Nov 20 21:55:13 efpies project[7202] <Warning>: >>>> selector: successfulLogin
Nov 20 21:55:13 efpies project[7202] <Warning>: >>>> target: <AppDelegate: 0x1f595a90>
Nov 20 21:55:13 efpies project[7202] <Warning>: >>>> object: <7b226d65 73736167 65223a22 5c753034 31325c75 30343435 5c753034 33655c75 30343334 205c7530 3434305c 75303433 305c7530 3433375c 75303434 305c7530 3433355c 75303434 385c7530 3433355c 75303433 64227d> NSConcreteMutableData
Nov 20 21:55:13 efpies project[7202] <Error>: -[AppDelegate invokeSelector:withObject:]: unrecognized selector sent to instance 0x1f595a90

Nov 20 21:56:12 efpies project[7205] <Warning>: >>>> selector: driversUpdated:
Nov 20 21:56:12 efpies project[7205] <Warning>: >>>> target: <DriversList: 0x1cd5ffd0>
Nov 20 21:56:12 efpies project[7205] <Warning>: >>>> object: (
    ) __NSArrayM
Nov 20 21:56:12 efpies project[7205] <Error>: -[DriversList invokeSelector:withObject:]: unrecognized selector sent to instance 0x1cd5ffd0

这些方法可用(甚至可以在头文件中显示)。怎么了?数据和对象100%正确

2 个答案:

答案 0 :(得分:1)

使用

[target performSelector:handler.successAction withObject:object]; 

这是在cocoa-touch中执行此操作的方法,因为NSObject将为您处理此问题。 查看Apple documentation了解详情。

答案 1 :(得分:0)

事实证明,invokeSelector:withObject:是静态库中的类别方法。静态库中的类别不会自动加载,因此您应该编写

-force_load $(BUILD_ROOT)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib_name.a

到目标Other linker flag中的Build settings字段,如果它编译为目标的依赖项。