Search code examples
iosuitableviewnsarraynsrangeexception

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


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.


Solution

  • 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;
    }