我不明白爲什麼我需要在某些塊中有一個弱自我,而其他人似乎工作正常。ARC:Dealloc不被稱爲
如果我對通知塊沒有弱自我引用,dealloc將不會被釋放。儘管如此,它仍然可以很好地工作。
//When using this, dealloc is NOT being called
[[NSNotificationCenter defaultCenter] addObserverForName:PROD_DONE object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[self hideAds];
}];
//When using this, dealloc IS being called
[_match endMatchInTurnWithMatchData:_match.matchData completionHandler:^(NSError *error) {
[self hideAds];
}];
如果我創建一個弱裁判的自我,它的工作原理:
__weak GameViewController *weakSelf = self;
[[NSNotificationCenter defaultCenter] addObserverForName:PROD_DONE object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[weakSelf hideAds];
}];
在您的第一個代碼示例中如何定義weakSelf? – 2013-03-13 14:01:42