ios - NSRangeException

时间:2012-12-17 23:31:50

标签: ios ios5 nsrangeexception

我在Crashalytics中遇到了这个例外:

0    CoreFoundation 
__exceptionPreprocess + 162
1    libobjc.A.dylib    
objc_exception_throw + 30
2    CoreFoundation 
-[NSException initWithCoder:]
3    CoreFoundation 
-[__NSCFArray objectAtIndex:] + 136
4    BusinessPlan ✭  BusinessController.m line 167
-[BusinessController tableView:didSelectRowAtIndexPath:] + 167
5    UIKit  
-[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 876
6    UIKit  
-[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 156
7    Foundation 
__NSFireDelayedPerform + 450
8    CoreFoundation 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
9    CoreFoundation 
__CFRunLoopDoTimer + 272
10   CoreFoundation 
__CFRunLoopRun + 1232
11   CoreFoundation 
CFRunLoopRunSpecific + 356
12   CoreFoundation 
CFRunLoopRunInMode + 104
13   GraphicsServices   
GSEventRunModal + 74
14   UIKit  
UIApplicationMain + 1120
15   BusinessPlan    main.m line 16
main + 16
16   BusinessPlan   
start

它被称为:

Exception Type: NSRangeException
Reason: -[__NSCFArray objectAtIndex:]: index (14) beyond bounds (14)

它只发生过一次所以我不确定如何重现它。但它发生在这段代码中:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{        
    NSDictionary *info = [topics_array objectAtIndex:indexPath.row]; 
    NSString *section_name = [info objectForKey:@"section_name"];
    NSString *solution_section_id = [info objectForKey:@"solution_section_id"];

    // PUT THESE ITEMS INTO THE SESSION
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

    [standardUserDefaults setObject:section_name forKey:@"section_name"];
    [standardUserDefaults setObject:solution_section_id forKey:@"solution_section_id"];

    [standardUserDefaults synchronize];

    [self performSegueWithIdentifier:@"BusinessToTopic" sender:self];
}

有谁知道如何防止将来发生这种情况以及为什么会发生这种情况?

编辑:

这是tableView numberOfRowsInSection

的代码
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{    
    return [tableLabels count]; 
}

谢谢!

0 个答案:

没有答案