错误是什么 "App Terminating"?
What is the error "App Terminating"?
错误:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [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;
}
此错误意味着您正试图从索引为 1 的数组中获取元素,但您超出了范围。
可能问题是:
[FavTablename objectAtIndex:indexPath.row]
在读取之前检查您的数组是否有一些元素。
为确定您的问题,请启用异常断点:
NSString *strfavarry = [NSString stringWithFormat:@"SELECT Title FROM %@ WHERE identifire='%@'",[FavTablename objectAtIndex:indexPath.row],[FavIdent objectAtIndex:indexPath.row]];
此行出现错误,因为您的行数大于这些数组计数值。
请检查您的 numberofrows 计数以及 FavTablename
和 FavIdent
数组计数是否相同。
正如您所说,FavTitle
和 Favtablename
具有相同数量的元素。所以尝试在cellForRowAtIndexPath
中放一个异常处理如下:-
if(FavTitle.count > indexPath.row){
cell.lbltitle.text=[FavTitle objectAtIndex:indexPath.row];
}
错误:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [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;
}
此错误意味着您正试图从索引为 1 的数组中获取元素,但您超出了范围。
可能问题是:
[FavTablename objectAtIndex:indexPath.row]
在读取之前检查您的数组是否有一些元素。
为确定您的问题,请启用异常断点:
NSString *strfavarry = [NSString stringWithFormat:@"SELECT Title FROM %@ WHERE identifire='%@'",[FavTablename objectAtIndex:indexPath.row],[FavIdent objectAtIndex:indexPath.row]];
此行出现错误,因为您的行数大于这些数组计数值。
请检查您的 numberofrows 计数以及 FavTablename
和 FavIdent
数组计数是否相同。
正如您所说,FavTitle
和 Favtablename
具有相同数量的元素。所以尝试在cellForRowAtIndexPath
中放一个异常处理如下:-
if(FavTitle.count > indexPath.row){
cell.lbltitle.text=[FavTitle objectAtIndex:indexPath.row];
}