解决performSelector may cause a leak because its selector is unknown警告

简介: 采用以下方法时会提示【performSelector may cause a leak because its selector is unknown】警告

问题


采用以下方法时会提示【performSelector may cause a leak because its selector is unknown】警告


[_controller performSelector:NSSelectorFromString(@"someMethod")];


解决方案


可采用以下方法消除


if (!_controller) { return; }
SEL selector = NSSelectorFromString(@"someMethod");
IMP imp = [_controller methodForSelector:selector];
void (*func)(id, SEL) = (void *)imp;
func(_controller, selector);


如果 selector 接收参数,或者有返回值,代码就改为如下:


SEL selector = NSSelectorFromString(@"processRegion:ofView:");
IMP imp = [_controller methodForSelector:selector];
CGRect (*func)(id, SEL, CGRect, UIView *) = (void *)imp;
CGRect result = _controller ?
  func(_controller, selector, someRect, someView) : CGRectZero;


目录
相关文章
|
5月前
|
开发工具 git
Stylelint——Unexpected unknown pseudo-class selector ":deep" selector-pseudo-class-no-unknown
新项目制定规范接入了stylelint,并通过husky在git提交时去触发检测修复,使用`:deep()`的时候却发现了报错;
196 1
|
Java Maven Android开发
成功解决FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE
成功解决FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE
|
Java
“Resource leak: ‘sc‘ is never closed”的解决及解释
“Resource leak: ‘sc‘ is never closed”的解决及解释
453 0
|
安全 Windows
CRITICAL_PROCESS_DIED
CRITICAL_PROCESS_DIED
4666 2
|
Java Android开发
Bad method handle type 7异常解决
在利用androidx版本写demo时,在添加了一些依赖后,遇到了`java.lang.ClassNotFoundException`bug,这就很奇怪了,我就添加rxjava3的依赖,就给我报这个错误。
error: static assertion failed: Signal and slot arguments are not compatible.
error: static assertion failed: Signal and slot arguments are not compatible.
error: static assertion failed: Signal and slot arguments are not compatible.
This error might indicate a memory leak if setState() is being called because another object is reta
This error might indicate a memory leak if setState() is being called because another object is reta
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
|
Android开发
Returned WKWebView was not created with the given configuration问题修复
调用WKWebView的时候,有些页面会打开新的一页,导致WKWebView出现闪退日志
275 0
unrecognized selector sent to instance的一类解决办法
unrecognized selector sent to instance的一类解决办法
160 0