ios - Where to remove observer for NSNotificationCenter in Objective-C -
i dont want add observer in viewdidappear , remove in viewdiddisappear.will not serve case.
i have tried doing in dealloc.
my root vc in navcontroller.then second vc pushed in navcontroller, addobserver notifications sent rootvc.the problem when pop secondvc dealloc not called or may somtimes not called alltogether.
- (void)viewdidload { [super viewdidload]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(newmessagesnotification:) name:_newmessagenotificationlistenername object:nil]; } - (void)newmessagesnotification:(nsnotification *)notification { //some implementation }
if not want remove in viewdiddisapear think should remove right after called navigationcotnroller pop methode. think can't tell exact moment when should remove because don't know when want remove , why isn't in viewwilldisapier or in viewdiddisapier.
Comments
Post a Comment