Ios [\uu NSArrayM objectAtIndex:]:索引9223372036854775807超出边界[0..0]'

Ios [\uu NSArrayM objectAtIndex:]:索引9223372036854775807超出边界[0..0]',ios,objective-c,xcode,Ios,Objective C,Xcode,当我尝试运行我的应用程序时,出现以下错误: Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 0]' 我真的不知道我的错误是什么。我还注意到,当我在我的表中存储日期时间数据时,它用括号括起来,引号从上午9:47变为上午9:47。我对Xcode真的

当我尝试运行我的应用程序时,出现以下错误:

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 0]'
我真的不知道我的错误是什么。我还注意到,当我在我的表中存储日期时间数据时,它用括号括起来,引号从上午9:47变为上午9:47。我对Xcode真的很陌生。我已经一周大了。这是我的密码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableCell";

SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

NSInteger indexOfAlarm = [self.dbManager.arrColumnNames indexOfObject:@"Time"];
   cell.timeLabel.text = [NSString stringWithFormat:@"%@",[[self.arrAlarmInfo objectAtIndex:indexPath.row]objectAtIndex:indexOfAlarm] ];
    return cell;
}
更改此代码


9223372036854775807的值是常量NSNotFound。它表示数组中不存在搜索的实例。要检查它,请添加if语句:

NSInteger indexOfAlarm = [self.dbManager.arrColumnNames indexOfObject:@"Time"];
if(indexOfAlarm != NSNotFound) // <-
{
   cell.timeLabel.text = [NSString stringWithFormat:@"%@",[[self.arrAlarmInfo objectAtIndex:indexPath.row]objectAtIndex:indexOfAlarm] ];
}
return cell;

如果您希望@Time始终在数组中,则必须找出它不在数组中的原因。

您是否引用了该文档?上面写着-我的目标指数:谢谢你的解释,阿明。我能用@Time解决我的问题。
 NSNumber *indexOfAlarm = [self.dbManager.arrColumnNames indexOfObject:@"Time"];

 cell.timeLabel.text = [NSString stringWithFormat:@"%@",[[self.arrAlarmInfo objectAtIndex:indexPath.row]objectAtIndex:indexOfAlarm.intValue] ];
NSInteger indexOfAlarm = [self.dbManager.arrColumnNames indexOfObject:@"Time"];
if(indexOfAlarm != NSNotFound) // <-
{
   cell.timeLabel.text = [NSString stringWithFormat:@"%@",[[self.arrAlarmInfo objectAtIndex:indexPath.row]objectAtIndex:indexOfAlarm] ];
}
return cell;