@weakify(self);
[[NSNotificationCenter defaultCenter] addObserverForName:xxx object:nil queue:[NSOperationQueuemainQueue]usingBlock:^(NSNotification*_Nonnullnote) {
@strongify(self);
}];
用这个方法添加观察者一定要使用weakSelf来打破循环引用,且不用removeObserver。
@weakify(self);
[[NSNotificationCenter defaultCenter] addObserverForName:xxx object:nil queue:[NSOperationQueuemainQueue]usingBlock:^(NSNotification*_Nonnullnote) {
@strongify(self);
}];
用这个方法添加观察者一定要使用weakSelf来打破循环引用,且不用removeObserver。
本文标题:NSNotificationCenter引起的循环引用
本文链接:https://www.haomeiwen.com/subject/iryflttx.html
网友评论