ios - Objective-C Notify When a New Record has been Added to the Database(sqlite) and Update the TableViewController -


i'm parsing data received remote notification , save on database within appdelegate. when received new remote notification while app running, uitableview doesn't updated new data.

i followed tutorial on how use sqlite. when comes on notifying when new element has been added database doesn't work on me since case appdelegate , uitableviewcontroller , tutorial's case viewcontroller , uitableviewcontroller

this how tutorial after implementing protocol

-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{     editinfoviewcontroller *editinfoviewcontroller = [segue destinationviewcontroller];     editinfoviewcontroller.delegate = self; } 

in case be

-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{     appdelegate *appdelegate = [segue destinationviewcontroller];     appdelegate.delegate = self; } 

and error:

cannot initialize variable of type 'appdelegate* __strong' rvalue of type' __kindofuiviewcontroller*'

what alternate can use prepareforsegue?

i'm kind of lost here appreciate can get.

yes error obvious because appdelegate not uiviewcontroller. trying push appdelegate object that's why got error.

in case if want save data of newly received notification in appdelegate create method in appdelegate itself.

then when receive notification call method save data database.

- (void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo {   if (application.applicationstate == uiapplicationstateactive) {       nslog(@"push received in active state: %@", userinfo);  }  else {      nslog(@"push received in inactive state: %@", userinfo);  }  [self savedatatodatabse:userinfo];  }    #pragma mark - private methods -(void)savedatatodatabse:(id)data {   // logic here    [[nsnotificationcenter defaultcenter] postnotificationname:@"newdatasaved" object:nil];   } 

in viewcontroller.m add observer in viewdidload method.

- (void)viewdidload{     [super viewdidload];     [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(reloadtable:) name:@"newdatasaved" object:nil]; }   -(void)reloadtable:(nsnotification)notification {     // logic here     [self.tableview reloaddata];  }   

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -