ios - Problems with uitableview sections using JSON -


i creating app demo purposes , have uitableview being populated json data , works fine. want create sections in table based on sessiondate app crashes error below:

terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[sessions objectforkey:]: unrecognized selector sent instance 0xac2b460'

here code parsing json:

-(void) retrievedata {     nsurl * url = [nsurl fileurlwithpath:[[nsbundle mainbundle]pathforresource:@"sessions-json.json" oftype:nil]];     nsdata * data = [nsdata datawithcontentsofurl:url];      json = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:nil];      //set our speakers array     sessionsarray = [[nsmutablearray alloc] init];      (int = 0; < json.count; i++) {     //create sessions object     nsstring * sid = [[json objectatindex:i] objectforkey:@"id"];     nsstring * sstatus = [[json objectatindex:i] objectforkey:@"sessionstatus"];     nsstring * sday = [[json objectatindex:i] objectforkey:@"sessionday"];     nsstring * sdate = [[json objectatindex:i] objectforkey:@"sessiondate"];     nsstring * stime = [[json objectatindex:i] objectforkey:@"sessiontime"];     nsstring * sname = [[json objectatindex:i] objectforkey:@"sessionname"];     nsstring * sspeaker1 = [[json objectatindex:i] objectforkey:@"sessionspeaker1"];     nsstring * sspeaker1company = [[json objectatindex:i] objectforkey:@"speaker1company"];     nsstring * sspeaker2 = [[json objectatindex:i] objectforkey:@"sessionspeaker2"];     nsstring * sspeaker2company = [[json objectatindex:i] objectforkey:@"speaker2company"];     nsstring * sspeaker3 = [[json objectatindex:i] objectforkey:@"sessionspeaker3"];     nsstring * sspeaker3company = [[json objectatindex:i] objectforkey:@"speaker3company"];     nsstring * sspeaker4 = [[json objectatindex:i] objectforkey:@"sessionspeaker4"];     nsstring * sspeaker4company = [[json objectatindex:i] objectforkey:@"speaker4company"];     nsstring * sspeaker5 = [[json objectatindex:i] objectforkey:@"sessionspeaker5"];     nsstring * sspeaker5company = [[json objectatindex:i] objectforkey:@"speaker5company"];     nsstring * sspeaker6 = [[json objectatindex:i] objectforkey:@"sessionspeaker6"];     nsstring * sspeaker6company = [[json objectatindex:i] objectforkey:@"speaker6company"];     nsstring * sdesc = [[json objectatindex:i] objectforkey:@"sessiondesc"];     nsstring * sitscecs = [[json objectatindex:i] objectforkey:@"itscecs"];     nsstring * ssessionid = [[json objectatindex:i] objectforkey:@"sessionid"];      sessions * mysessions = [[sessions alloc] initwithid:sid andsessionstatus:sstatus andsessionday:sday andsessiondate:sdate andsessiontime:stime andsessionname:sname andsessionspeaker1:sspeaker1 andspeaker1company:sspeaker1company andsessionspeaker2:sspeaker2 andspeaker2company:sspeaker2company andsessionspeaker3:sspeaker3 andspeaker3company:sspeaker3company andsessionspeaker4:sspeaker4 andspeaker4company:sspeaker4company andsessionspeaker5:sspeaker5 andspeaker5company:sspeaker5company andsessionspeaker6:sspeaker6 andspeaker6company:sspeaker6company andsessiondesc:sdesc anditscecs:sitscecs andsessionid:ssessionid];      //add our sessions object our sessionsarray     [sessionsarray addobject:mysessions];       nssortdescriptor *sort = [nssortdescriptor sortdescriptorwithkey:@"sessiondate" ascending:yes];     [sessionsarray sortusingdescriptors:[nsarray arraywithobject:sort]];       }    [self.mytableview reloaddata];  } 

here's code in numberofsectionsintableview:

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     //#warning potentially incomplete method implementation.     // return number of sections.     //return 1;      if (tableview == self.mytableview) {     return self.sessionsarray.count;     }     else     {         [self searchthroughdata];         return self.results.count;     }   } 

here's code in numberofrowsinsection:

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     // return number of rows in section.     //return sessionsarray.count;      if (tableview == self.mytableview) {     return self.sessionsarray.count;     }     else     {         [self searchthroughdata];         return self.results.count;     }    } 

here's code in titleforheaderinsection:

- (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section {      return [[sessionsarray objectatindex:section] objectforkey:@"sessiondate"]; } 

i've been working objective c couple months, i'm overlooking basic. help.

sessionsarray contains sessions objects, when use you're treating contains dictionaries. use same code section count , row count. so, looks intend have 2 sets / levels of data have 1 , you're trying use 2 things.

you need decide sessionsarray used , keep that. sections represent , how represent rows in each section. configure data structure match that.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -