ios - NSNotificationCenter crashes my app -


i've added nsnotificationcenter observer calls 2 selectors same name on 2 different view controllers.

it works, when run app crashes error message:

thread 1: exc_bad_access (code=1, address=0x18) 

or

thread 1: exc_bad_access (code=exc_i386_gpflt) 

image

anyone has idea why crashes? thank you!

.

my code:

fetchfromparse:

-(void)sendallstores {     [[nsnotificationcenter defaultcenter]postnotificationname:@"getstoresarrays" object:nil userinfo:self.storesdict]; } 

firstvc.m:

- (void)viewdidload {     [[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(getstoresarrays:) name:@"getstoresarrays" object:nil]; }  -(void)getstoresarrays:(nsnotification*)notification {     nslog(@“working”);   } 

secondvc.m:

-(void)preparearrays {     [[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(getstoresarrays:) name:@"getstoresarrays" object:nil]; } -(void)getstoresarrays:(nsnotification*)notification {     nslog(@“working”); } 

appdelegate.m:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     self.secvc=[[secondvc alloc] init];     [self.secvc preparearrays];      fetchfromparse *fetchfromparseobj=[[fetchfromparse alloc] init];     [fetchfromparseobj getstoresfromparse];      return yes; } 

notification crashes

typically might see crash of nature if attempt close view controller without removing observer. part of answer provided mr. patil, absolutely required. use-case vary , how remove observer. if remove might end crashing if try reference related objects.

so might want remove self.storesdict object or @ least verify not nil before using it.

debugging

here's quick tutorial on debugging xcode. it's older version should speed quickly. can review apple docs more on collecting crash logs.

logs

you should go reports navigator , copy bit more of log can determine more precise cause of issue. can add breakpoint right before faulty code , step through issue. copy debug console if nothing else.

getting crash log

you can open xcode go window menu select devices. select attached device (iphone/ipad) , click view device logs button. list select app name/crash date. copy data question.

more information

the more information provide on crashes more can you. suspect answer either trying access nil or not releasing observer @ right time. might not appropriate release observer when view disappears have not provided enough information make obvious.

how different view controllers work together? notifications causing crash?? put breakpoint @ post notification , in each selector , debug app until crashes. need identify conditions precede crash. i'll refine answer if let me know when update question.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -