uiviewcontroller - iOS - Using dealloc to remove observer -
i have basic question regarding removing observer.
i have viewcontroller parent class inherited 3 viewcontroller child classes. eg. bookvc -> bookhotelvc, bookflightvc, booktrainvc
here, added observer in viewdidload
of parent class (i [super viewdidload]
in child viewcontrollers) notifies method written in parent class. code-
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(bookingcompleted:) name:@"bookingcompleted" object:nil];
now want remove observer when move away of child viewcontrollers, can't write [super dealloc]
in dealloc
of each child viewcontroller because arc doesn't permit this.
how can remove observer set ? because whenever move child viewcontroller, new observer added causes weird things (like, calling method twice/thrice... - invoking alert twice/thrice...).
kindly suggest.
removing observers in dealloc
fine, not call [super dealloc]
(as saw, arc enabled, compiler won't let you), write:
- (void)dealloc { [self removeyourobservers]; }
Comments
Post a Comment