ios - popViewController, dealloc and removeObserver -


i'm having problem of right place remove observer nsnotificationcenter

// detailofsomethingviewcontroller @implementation detailofsomethingviewcontroller  - (void)viewdidload {     [[nsnotificationcenter defaultcenter] addobserver:self                                            selector:@selector(showmoredetail:)                                            name:some_notification_name                                            object:sender]; }  - (void)dealloc {     [[nsnotificationcenter defaultcenter] removeobserver:self]; }  - (void)showmoredetail:(id)sender {     [self presentviewcontroller:[[moredetailviewcontroller alloc] init] animated:no completion:nil]; } 

during test run, try pop viewcontroller's instance navigation stack , push new instance onto stack. found dealloc method of instance has been popped navigation stack doesn't called right away.

so, during moment before dealloc gets called, if some_notification_name has been sent out source, popped instance still listening , responding calling showmoredetail (note : 1 on navigation stack works fine) , trying present moredetailviewcontroller while not in application window. warning has been raise.

warning: attempt present <detailofsomethingcontroller: 0xac2c3e0> on <moredetailviewcontroller: 0xac268f0> view not in window hierarchy! 

i can check existence on navigation stack of view controller instance there proper way remove observer right away when got popped? can't put removal code in viewdiddisappear or viewwilldisappear since controller has notify , it's not topviewcontroller of stack.

also, adding code check before present view has added several places inside controller since showmoredetail isn't method presentation, there more similar methods.

any help, suggestion welcome.

regards

in showmoredetail: check if uinavigationcontroller's topviewcontroller property equals self , if continue.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -