ios - If JSON response is "true", don't show results in Table View -


i'm getting json:

{     "timestamp": "2013-05-03t22:03:45z",     "resultsoffset": 0,     "status": "success",     "resultslimit": 10,     "breakingnews": [],     "resultscount": 341,     "feed": [{         "headline": "this first headline",         "lastmodified": "2013-05-03t21:33:32z",         "premium": false,         "links": {             "api": { 

and use load in uitableview:

@property (strong, nonatomic) nsarray *headlinesarray;  - (void)viewdidload {     [[rkobjectmanager sharedmanager] loadobjectsatresourcepath:[nsstring stringwithformat:@"/now/?leafs=%@&teas=%@&apikey=xxxxx", leafabbreviation, teaid] usingblock:^(rkobjectloader *loader) {             loader.ondidloadobjects = ^(nsarray *objects){                  premiumarray = objects;                  [_tableview reloaddata];              };             [loader.mappingprovider setmapping:[feed mapping] forkeypath:@"feed"];             loader.ondidloadresponse = ^(rkresponse *response){                 //nslog(@"bodyasstring: %@", [response bodyasstring]);             };         }];      }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"standardcell";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      feed *feedlocal = [headlinesarray objectatindex:indexpath.row];     nsstring *headlinetext = [nsstring stringwithformat:@"%@", feedlocal.headline];     cell.textlabel.text = headlinetext;      return cell; } 

headline class model:

@property (strong, nonatomic) nsstring *headline; @property (strong, nonatomic) links *linksheadline; 

is there way check if premium true in json, not show headline in uitableview?

edit 1 added @property (strong, nonatomic) nsarray *premiumarray; pulling in correct data associated premium, need looking thru array links true uitableview won't show headlines premium = true.

edit 2 posted viewdidload code above.

edit 3

feed.h

@property (nonatomic, strong) nsstring *headline; @property (nonatomic, strong) nsstring *premium; 

feed.m

+ (rkobjectmapping *)mapping {     rkobjectmapping *objectmapping = [rkobjectmapping mappingforclass:[self class] usingblock:^(rkobjectmapping *mapping) {         [mapping mapkeypathstoattributes:          @"headline", @"headline",          @"premium", @"premium",          nil];     }];     return objectmapping; } 

edit

i added per answers, still couldn't working, thoughts? @property (strong, nonatomic) nsarray *premiumarray; @property (strong, nonatomic) nsmutablearray *mymutable;   [[rkobjectmanager sharedmanager] loadobjectsatresourcepath:[nsstring stringwithformat:@"/now/?leagues=%@&teams=%@&apikey=5qqpgrsnfy65vjzswgjfkgwy", leagueabbreviation, teamid] usingblock:^(rkobjectloader *loader) {         loader.ondidloadobjects = ^(nsarray *objects){              //sports = objects;             premiumarray = objects;              [_tableview reloaddata];          };         [loader.mappingprovider setmapping:[feed mapping] forkeypath:@"feed"];         loader.ondidloadresponse = ^(rkresponse *response){             //nslog(@"bodyasstring: %@", [response bodyasstring]);         };     }];  self.mymutable = [[premiumarray filteredarrayusingpredicate:[nspredicate predicatewithformat:@"premium = yes"]] mutablecopy]; 

you need create sort of uitableview data source. having uitableview handle more difficult setting data structure , pass data in uitableview data source.

a nsmutablearray work fine need done. whatever json parser toolkit using, given arrayed response, looks stored in headlinesarray, each containing example code above.

you need enumerate through headlinesarray , if [post objectforkey:@"premium"] == true add nsmutablearray.

place of in viewdidload processed before uitableview built , in tableview need access newly built array.

.h @interface yourclass: yourclasssuperclass {    nsmutablearray *a; }  .m  //in viewdidload  = [nsmutablearray array]; //allocs , inits new array.  (feed *f in headlinesarray) //for feeds in headlines array. (f local var) {   //check if premium == true. if yes, add a. }  //then in data source methods use array named 'a'  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"standardcell";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      feed *feedlocal = [a objectatindex:indexpath.row]; //replaced headlinesarray     nsstring *headlinetext = [nsstring stringwithformat:@"%@", feedlocal.headline];     cell.textlabel.text = headlinetext;      return cell; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -