开发者

Last item in UITableView unreachable with textLabel.text

I'm populating a UITableView with an array of items I retrieve from the interwebs.

The code in question selects an item from a list populated from an array from the interwebs, then sends a request back to a different php script->sql table etc based on the item selected. The issue i'm having is the entire list is populating correctly, but when using the last item in the list/tableview the array.textLabel.text is apparently.. non existant. Everything sends off fine, but this one last item (doesnt matter how many items i have in the array the very last one just doesnt ... remain or something) and it selects nothing.

Then when sending the 2nd request, it gives me an out of bounds error because the last item doesn't exist and it says im trying to pull something thats not there.

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

This is how it makes the array it uses to populate:

NSArray *listItems开发者_Python百科 = [parsedOutput componentsSeparatedByString:@","];
restList = [[NSArray alloc] initWithArray:listItems];

the row count is based on [restList count]; etc. and to call the text I use:

restName = [tableView cellForRowAtIndexPath:indexPath];
sendName = restName.textLabel.text;

Any idea why the very last element doesn't seem to exist even though its listing and selectable?


The error tells you exactly what's happening. You are attempting to access an index that is outside the bounds of the array. So either you are accessing the wrong array or you are accessing 1 past the actual end of the array. Try to NSLog the array just before the line the error comes up and see if it indeed has the right elements in it as well as output index.row you are trying to access keeping in mind that arrays are zero-indexed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜