ios - Data from API call and jsonobject is not carrying over when called -
i'm calling api , it's jsonobject in segue, , trying push view controller, it's not carrying data. in below code prints fine in call, other 2 prints come null.
is there i'm missing make data persistent?
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"showchangedetail"]) { nsindexpath *indexpath = nil; bnritem *item = nil; //bditemchangedetailapi *itemapi = nil; nsarray *items = [[bnritemstore sharedstore] allitems]; if (self.searchdisplaycontroller.active) { indexpath = [self.searchdisplaycontroller.searchresultstableview indexpathforselectedrow]; item = [searchresults objectatindex:indexpath.row]; } else { indexpath = [self.tableview indexpathforselectedrow]; //item = items[indexpath.row]; item = [items objectatindex:indexpath.row]; } nslog(@"111111%@", self.apiitem); [self fetchfeedapichangedetail]; nslog(@"222222%@", self.apiitem); bdchangeapprovecontroller *destviewcontroller = segue.destinationviewcontroller; destviewcontroller.itemapi = self.apiitem; } } - (void)fetchfeedapichangedetail { //nsstring *changeorder = changeorder; // nsstring *requeststring = [@"http://url.com]; nsstring *requeststring = @"http://url.com"; nsurl *url = [nsurl urlwithstring:requeststring]; nsurlrequest *req = [nsurlrequest requestwithurl:url]; nsurlsessiondatatask *datatask = [self.session datataskwithrequest:req completionhandler: ^(nsdata *data, nsurlresponse *response, nserror *error){ nsdictionary *jsonobject1 = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil]; //nslog(@"%@", jsonobject1); self.apiitem = jsonobject1[@"codetail"]; nslog(@"%@", self.apiitem); }]; [datatask resume]; } - (void) tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // show loading indicator __weak typeof(self) weakself = self; [[bnritemstore sharedstore] fetchfeedapichangedetail:^(nsarray *array, nserror *err) { [weakself performseguewithidentifier:@"showchangedetail" sender:weakself]; // hide loading indicator }]; }
Comments
Post a Comment