objective c - Selector don't getting notification from NSNotificationCenter (iOS) -
i sending notification class inherits nsobject using nsnotificationcenter.
the notification should sent 2 viewcontroller it's being sent 1 of them.
my code:
fetchfromparse:
-(void)sendallstores { [[nsnotificationcenter defaultcenter]postnotificationname:@"getstoresarrays" object:nil userinfo:self.storesdict]; }
firstvc.m (working):
- (void)viewdidload { [[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(getstoresarrays:) name:@"getstoresarrays" object:nil]; } -(void)getstoresarrays:(nsnotification*)notification { nslog(@“working”); //working }
secondvc.m (not working):
-(void)preparearrays { [[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(getstoresarrays:) name:@"getstoresarrays" object:nil]; } -(void)getstoresarrays:(nsnotification*)notification { nslog(@“not working”); //not working }
appdelegate.m:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { secondvc *secvc=[[secondvc alloc] init]; [secvc preparearrays]; fetchfromparse *fetchfromparseobj=[[fetchfromparse alloc] init]; [fetchfromparseobj getstoresfromparse]; return yes; }
note: xcode shows me error message "firstvc not registered observer".
the logic code not correct. posting notification , have made 2 classes observer, lead unpredictable results. should have 1 class observer notification.
Comments
Post a Comment