我用2 NSNotificationCenter
,为了避免保留周期我已经创建了一个weakSelf这样的:__unsafe_unretained AugmentedRealityViewController *weakSelf = self;
无法删除NSNotificationCenter
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
if (weakSelf.architectWorldNavigation.wasInterrupted) {
[weakSelf.architectView reloadArchitectWorld];
}
[weakSelf startWikitudeSDKRendering];
}];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[weakSelf stopWikitudeSDKRendering];
}];
的问题是,即使我删除它们dealloc
内他们一直被解雇和应用程序崩溃。
的dealloc
内部,以便去除NSNotificationCenter
我使用下面的代码:
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.architectView removeFromSuperview];
}
,当我离开的ViewController但通知仍然有效,它被称为..谁能告诉我什么是错的代码以及如何解决这个问题?
你在哪里添加观察者?在应用程序代表? –
@ Mr.T在我的ViewDidLoad – Signo
离开视图控制器,你的意思是什么?这是否意味着回家或转移到另一个VC? –