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


目录
相关文章
|
6月前
|
Android开发
【Bug】Android resource linking failed和error: failed linking references.
【Bug】Android resource linking failed和error: failed linking references.
|
3月前
|
开发工具 git
Stylelint——Unexpected unknown pseudo-class selector ":deep" selector-pseudo-class-no-unknown
新项目制定规范接入了stylelint,并通过husky在git提交时去触发检测修复,使用`:deep()`的时候却发现了报错;
125 1
|
6月前
【Bug】ERROR ResizeObserver loop completed with undelivered notifications.
【Bug】ERROR ResizeObserver loop completed with undelivered notifications.
|
iOS开发
Xcode报错Expected selector for Objective-C and Expected method body
Xcode报错Expected selector for Objective-C and Expected method body
219 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出现闪退日志
260 0
unrecognized selector sent to instance的一类解决办法
unrecognized selector sent to instance的一类解决办法
141 0
|
Android开发
【错误记录】前台进程报错 ( Bad notification for startForeground invalid channel for service notification )
【错误记录】前台进程报错 ( Bad notification for startForeground invalid channel for service notification )
1408 0
【错误记录】前台进程报错 ( Bad notification for startForeground invalid channel for service notification )
|
C语言
performSelector消除警告'undeclared selector'的方法
performSelector消除警告'undeclared selector'的方法
540 0
|
Java
Preference跳转activity出错Unable to find explicit activity class
使用Preference可以非常方便的实现类似设置页面这样的菜单布局,甚至可以不需写java代码。那么可以在Preference中直接添加页面跳转么?其实非常简单,在Preference添加intent标签即可
523 0