本文主要是介绍避免程序出现 unrecognized selector 闪退问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
给NSObject添加分类
加入代码
+(void)load{
Method method1 = class_getInstanceMethod(self.class, @selector(methodSignatureForSelector:));
Method method2 = class_getInstanceMethod(self.class, @selector(mymethodSignatureForSelector:));
method_exchangeImplementations(method1, method2);
Method method3 = class_getInstanceMethod(self.class, @selector(forwardInvocation:));
Method method4 = class_getInstanceMethod(self.class, @selector(myforwardInvocation:));
method_exchangeImplementations(method3, method4);
}
-(NSMethodSignature*)mymethodSignatureForSelector:(SEL)selector
{
NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:@encode(void)];
return signature;
}
- (void)myforwardInvocation:(NSInvocation *)invocation {
}
做法比较霸道
参考:https://www.jianshu.com/p/c89b2716d60d
这篇关于避免程序出现 unrecognized selector 闪退问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!