ios - Error populating TableView with array: index 1 beyond bounds [0 .. 0] -
i trying populate uitableview nsarray.
i'm building app in users can search companies, , search results returned database in array. makes can never predict how big array be.
when i'm testing app, gets stuck if there 1 search result. error:
terminating app due uncaught exception 'nsrangeexception', reason: '*** -[__nsarrayi objectatindex:]: index 1 beyond bounds [0 .. 0]' *** first throw call stack: (0x1c9a012 0x10d7e7e 0x1c4fb44 0x5268 0xd68fb 0xd69cf 0xbf1bb 0xcfb4b 0x6c2dd 0x10eb6b0 0x2296fc0 0x228b33c 0x228b150 0x22090bc 0x220a227 0x22acb50 0x31edf 0x1c62afe 0x1c62a3d 0x1c407c2 0x1c3ff44 0x1c3fe1b 0x1bf47e3 0x1bf4668 0x1bffc 0x1ddd 0x1d05) libc++abi.dylib: terminate called throwing exception this code looks like:
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // return number of sections. return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. return companies.count; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsstring *celltitle=nil; if([companiesarray count]>1){ celltitle = [[companiesarray objectatindex:indexpath.row] objectforkey:@"companyname"]; } else { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; cell.textlabel.text = [[companiesarray objectatindex:indexpath.row] objectforkey: @"companyname"]; cell.detailtextlabel.text = [[companiesarray objectatindex:indexpath.row] objectforkey: @"companycity"]; return cell; } } what should prevent error, if array contains 1 result?
try one
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. return companiesarray.count; }
Comments
Post a Comment