解决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;


目录
相关文章
|
26天前
【Bug】ERROR ResizeObserver loop completed with undelivered notifications.
【Bug】ERROR ResizeObserver loop completed with undelivered notifications.
|
6月前
|
小程序 开发者
小程序报错-ReferenceError: regeneratorRuntime is not defined
小程序报错-ReferenceError: regeneratorRuntime is not defined
37 0
|
7月前
|
人工智能 自然语言处理 前端开发
小程序引入组件库报错VM128:1 Unhandled promise rejection TypeError: WebAssembly.instantiate(): Argument 0 must
小程序引入组件库报错VM128:1 Unhandled promise rejection TypeError: WebAssembly.instantiate(): Argument 0 must
22 0
|
内存技术
|
Java Android开发
编译时出现stripped of unavailable superclass
编译时出现stripped of unavailable superclass
73 0
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
|
Android开发
Returned WKWebView was not created with the given configuration问题修复
调用WKWebView的时候,有些页面会打开新的一页,导致WKWebView出现闪退日志
227 0
unrecognized selector sent to instance的一类解决办法
unrecognized selector sent to instance的一类解决办法
101 0
|
iOS开发
Xcode报错Expected selector for Objective-C and Expected method body
Xcode报错Expected selector for Objective-C and Expected method body
184 0
Xcode报错Expected selector for Objective-C and Expected method body
|
Java Android开发
Bad method handle type 7异常解决
在利用androidx版本写demo时,在添加了一些依赖后,遇到了`java.lang.ClassNotFoundException`bug,这就很奇怪了,我就添加rxjava3的依赖,就给我报这个错误。