在我viewDidLoad
,添加我的控制器作爲觀察員兩個通知:我需要從NSNotificationCenter中刪除觀察者一次,還是一次添加觀察者?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:NetworkStatusChangedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkLocationStatus:) name:LocationStatusChangedNotification object:nil];
在我dealloc
,應該有一次,我將其刪除,或兩次? removeObserver方法似乎沒有指定特定的通知。
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] removeObserver:self]; // is this required?
您還可以刪除觀察者特定通知, /或使用'removeObserver:name:object:'的對象。如果觀察者觀察到其他通知,這將使觀察者保持在通知中心。 – Jasarien
@Jasarien我認爲你已經添加了評論,並且我編輯了我的答案,以便同時說出同樣的內容:) –
偉大的思想家們都認爲:P – Jasarien