When I use -addObserverForName: object: queue: usingBlock:
for NSNotificationCenter
in the -viewDidLoad:
method of my view controller, the -dealloc
method ends up not being called.
(When I remove -addObserverForName: object: queue: usingBlock:
, -dealloc
is called again.)
Using -addObserver: selector: name: object:
doesn't seem to have this problem. What am I doing wrong? (My project is using ARC.)
Below is an example of my implementation, in case I'm doing something wrong here:
[[NSNotificationCenter defaultCenter] addObserverForName:@"Update result"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
updateResult = YES;
}];
Thanks in advance for any help.
I've tried adding the following (to no avail):
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([self isMovingFromParentViewController]) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
}
[self updateType:@"someType"];
that have the same problem. Is a retain cycle also happening here? Also, can you be more specific on how to "create a weak or unsafe_unretained reference to that instance and its variable"? I'm still relatively new at this... Thanks! – Bigamous