Search code examples
iosuitableviewnsmutablearraynsrangeexception

What is the error "App Terminating"?


Error:

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

Here my code:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"AartiTableViewCell";
    AartiTableViewCell *cell = (AartiTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AartiTableViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.btnFav.userInteractionEnabled=YES;            
    }

    NSString *strfavarry = [NSString stringWithFormat:@"SELECT  Title FROM %@ WHERE identifire='%@'",[FavTablename objectAtIndex:indexPath.row],[FavIdent objectAtIndex:indexPath.row]];
    FavTitle = [FavData lookupAllForSQL:strfavarry];

    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.index = indexPath.row;
    cell.btnFav.tag=indexPath.row;
    [cell.btnFav setBackgroundImage:[UIImage imageNamed:@"unfav.png"] forState:UIControlStateNormal];
    [cell.btnFav addTarget:self action:@selector(handleFavouriteButton:) forControlEvents:UIControlEventTouchUpInside];        
    cell.lbltitle.text=[FavTitle objectAtIndex:indexPath.row];   

    return cell;
}

Solution

  •  NSString *strfavarry = [NSString stringWithFormat:@"SELECT  Title FROM %@ WHERE identifire='%@'",[FavTablename objectAtIndex:indexPath.row],[FavIdent objectAtIndex:indexPath.row]];
    

    This line is given the error because your numberofrows count is greater than these array count value.

    please check your numberofrows count and FavTablename and FavIdent array count is same or not.