UITableView with NSArray gives "index beyond bounds" error -


i have experience using tableviews. time, tried loading array (well, technically, dictionary, allkeys parameter nsarray), however, exception

-[__nsarrayi objectatindex:]: index 10 beyond bounds [0 .. 9] 

now, array 11 keys long, means counted 10 (since obj-c counts 0 well). here says it's count 9. have tried several different methods:

  • moving initialisation of dictionary - (void)awakefromnib
  • creating separate nsarray keys
  • just listing 11

but give me exception!

update

i noticed of saying array 10 objects long, if set 10, 1 object missing:

as can see, there 11 keys

the breakpoint tells 11...

enter image description here

there's no "acceleration x" item when using 10 items, see?

enter image description here

and nslogsays differently 10, in same method returning amount of rows

the fact of matter array 10 items long. comments above aren't saying "you should remove "acceleration x" make 10 items long", they're saying "you're mistaken in belief array 11 items long".

without seeing more code, it's difficult what's going on here; anyway, shouldn't using -allvalues, because ordering in array undefined, makes unsuitable use backing table view.

instead, should keep array of keys of dictionary in whatever order want them display, , reference _items[key] directly.

for example:

_keys =  @[     @"red",     @"orange",     @"yellow",     @"green",     @"blue",     @"indigo",     @"violet" ];  _dictionary =  @{     @"blue": @"battle",     @"green": @"gave",     @"indigo": @"in",     @"orange": @"of",     @"red": @"richard",     @"violet": @"vain"     @"yellow": @"york", };  - (nsstring *)labeltextforindexpath:(nsindexpath *)indexpath {     return _keys[indexpath.row]; }  - (nsstring *)detaillabeltextforindexpath:(nsindexpath *)indexpath {     return _dictionary[_keys[indexpath.row]]; } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -