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


目录
相关文章
|
2月前
|
开发工具 git
Stylelint——Unexpected unknown pseudo-class selector ":deep" selector-pseudo-class-no-unknown
新项目制定规范接入了stylelint,并通过husky在git提交时去触发检测修复,使用`:deep()`的时候却发现了报错;
52 1
|
5月前
|
JavaScript 前端开发
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 内存溢出问题
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 内存溢出问题
85 1
|
12月前
|
人工智能 自然语言处理 前端开发
小程序引入组件库报错VM128:1 Unhandled promise rejection TypeError: WebAssembly.instantiate(): Argument 0 must
小程序引入组件库报错VM128:1 Unhandled promise rejection TypeError: WebAssembly.instantiate(): Argument 0 must
50 0
|
iOS开发
Xcode报错Expected selector for Objective-C and Expected method body
Xcode报错Expected selector for Objective-C and Expected method body
212 0
Xcode报错Expected selector for Objective-C and Expected method body
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出现闪退日志
254 0
unrecognized selector sent to instance的一类解决办法
unrecognized selector sent to instance的一类解决办法
128 0
|
C语言
performSelector消除警告'undeclared selector'的方法
performSelector消除警告'undeclared selector'的方法
531 0
如何处理错误消息Unable to install breakpoint due to missing line number attributes
如何处理错误消息Unable to install breakpoint due to missing line number attributes
181 0
如何处理错误消息Unable to install breakpoint due to missing line number attributes