当我在我的视图控制器的
使用
以下是我的实现示例,以防我在这里做错了什么:
感谢您的帮助。我尝试添加以下内容(但没有成功):
-viewDidLoad:
方法中使用-addObserverForName: object: queue: usingBlock:
来监听NSNotificationCenter
时,-dealloc
方法最终没有被调用。(当我移除-addObserverForName: object: queue: usingBlock:
时,-dealloc
会再次被调用。)使用
-addObserver: selector: name: object:
似乎没有这个问题。我做错了什么?(我的项目使用ARC。)以下是我的实现示例,以防我在这里做错了什么:
[[NSNotificationCenter defaultCenter] addObserverForName:@"Update result"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
updateResult = YES;
}];
感谢您的帮助。我尝试添加以下内容(但没有成功):
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([self isMovingFromParentViewController]) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
}