-2

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;
}
seggy
  • 1,176
  • 2
  • 18
  • 38

3 Answers3

0

This error means you are trying to get an element from an array at index 1 and you are going out of bounds.

Probably the problem is:

[FavTablename objectAtIndex:indexPath.row]

check if your array has some elements before reading from it.

To be sure of your problem enable the exception breakpoint:

enter image description here

Marco Santarossa
  • 4,058
  • 1
  • 29
  • 49
0
 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.

Pooja Srivastava
  • 721
  • 1
  • 6
  • 19
0

As you said that FavTitle and Favtablename have same number of elements. So try to put a exception handling in cellForRowAtIndexPath as follows:-

if(FavTitle.count > indexPath.row){
        cell.lbltitle.text=[FavTitle objectAtIndex:indexPath.row];
    }
pkc456
  • 8,350
  • 38
  • 53
  • 109