什么是“应用程序终止”的错误?
问题描述:
*终止应用程序由于未捕获的异常 'NSRangeException',原因: '* - [__ NSArrayM objectAtIndex:]:索引1超出范围[0 .. 0]'
这里我代码:
-(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;
}
答
NSString *strfavarry = [NSString stringWithFormat:@"SELECT Title FROM %@ WHERE identifire='%@'",[FavTablename objectAtIndex:indexPath.row],[FavIdent objectAtIndex:indexPath.row]];
此行给出了错误,因为你的numberofrows计数大于这些阵列计数值更大。
请检查您的numberofrows count并FavTablename
和FavIdent
阵列数是否相同。
+0
所有元素是我将检查这两个数组相同@Pooja Srivastava – seggy
答
正如你所说,FavTitle
和Favtablename
具有相同数量的元素。因此,尝试把一个异常处理cellForRowAtIndexPath
如下: -
if(FavTitle.count > indexPath.row){
cell.lbltitle.text=[FavTitle objectAtIndex:indexPath.row];
}
你有什么问题部分误差与?调试器将显示问题的确切位置。 –
由于索引1超出范围[0..0] – seggy
在哪里填充FavTablename和FavIdent数组,因为此数组可能少于您的numberofrows数。 –