- [__ NSArrayM objectAtIndex:]:索引11超出界限[0 .. 10]'目标c

时间:2017-03-06 11:13:28

标签: ios objective-c iphone xcode nsarray

大家都知道if(indexPath.row == 3)部分的问题 - [__ NSArrayM objectAtIndex:]:索引11超出界限[0 .. 10]'。无法确切地解决问题所在。以下是我的代码

if(indexPath.row==3)
{
    cell.textLabel.text = @"Subject";
    cell.detailTextLabel.text=[empDict objectForKey:@"Subject"];
}
if(indexPath.row==3)
{
    cell.textLabel.text = @"Education";
    cell.detailTextLabel.text=[empDict objectForKey:@"Education"];
}


NSArray *times = [empDict objectForKey:@"ClassTimings"];

NSString *stgmt = [[times objectAtIndex:indexPath.row]objectForKey:@"GMT"];

NSString *strtime = [[times  objectAtIndex:indexPath.row]objectForKey:@"Time"];

NSString *strtimeZone = [[times  objectAtIndex:indexPath.row]objectForKey:@"TimeZone"];

NSString *str = [@[stgmt, strtime, strtimeZone] componentsJoinedByString:@" "];
if(indexPath.row==3)
{
    cell.textLabel.text = @"Times To Take";
    cell.detailTextLabel.text=[NSString stringWithFormat:@"%@",str];

}

return cell;

2 个答案:

答案 0 :(得分:1)

您的问题不在"if(indexPath.row==3)"

你从以下任何一行得到错误

NSString *stgmt = [[times objectAtIndex:indexPath.row]objectForKey:@"GMT"];

NSString *strtime = [[times  objectAtIndex:indexPath.row]objectForKey:@"Time"];

NSString *strtimeZone = [[times  objectAtIndex:indexPath.row]objectForKey:@"TimeZone"];

您尝试访问12th element的{​​{1}}数组indexPath.row==12时没有'times' ...

希望有所帮助......

答案 1 :(得分:0)

这个问题是因为你试图访问11个元素数组的第12个元素。  在您的代码中,如果times数组没有12个元素,并且您尝试访问第12个元素,则可能会发生此问题。如果indexpath.row = 12并且您尝试按[times objectAtIndex:indexPath.row]访问第12个对象,则会导致此错误。