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
nsarraykeys - just listing
11
but give me exception!
update
i noticed of saying array 10 objects long, if set 10, 1 object missing:

the breakpoint tells 11...

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

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
Post a Comment