[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'

10.2k views Asked by At

This is the log of my nsarray with two strings.

GROUPSFORDISPLAY (
"Serie A",
"Serie B"

And this is exactly what I want do show in tableviewcells, but app is crashing instead. The code I'm using is:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath object:(PFObject *)object {
    static NSString *CellIdentifier = @"Cell";

    PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }



    NSString *series = [_seriesForDisplay objectAtIndex:indexPath.row];
    cell.textLabel.text = series;

Thanks.

1

There are 1 answers

4
Dharmbir Singh On BEST ANSWER

It says your array's count is 2 and you're accessing 3rd item . So please try to use this one.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return _seriesForDisplay.count;
}