0

I get this exception in my 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

and it is called this:

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

It only happened once so I am not sure how to reproduce it. But it happened in this code:

- (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];
}

Would anyone know how to prevent this from happening in the future and why it is happening?

EDIT:

This is the code for tableView numberOfRowsInSection

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

Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284
  • 1
    topics_array contains 14 items only, you're trying to access the 15th one. –  Dec 17 '12 at 23:33
  • Are you programmatically causing the table to get selected? – ThomasW Dec 17 '12 at 23:35
  • I thought I was doing this programatically and this sort of thing was not possible. What code should I add to my question to make it more debuggable? – Genadinik Dec 17 '12 at 23:39
  • Show your code for `tableView:numberOfRowsInSection:`. It's important that your use of the data model is the same. – rmaddy Dec 18 '12 at 00:46
  • @rmaddy did not notice your message earlier. Just posted that code in my original question. – Genadinik Dec 18 '12 at 02:19
  • How do you know that tableLabels and topics_array are the same size? – Hot Licks Dec 18 '12 at 02:45
  • @HotLicks I am actually not certain. I did not write that code, and trying to understand it. – Genadinik Dec 18 '12 at 03:05
  • In general, there are supposed to be a set number of rows in that screen. So they are always kind of expected to have the same number of rows. It doesn't change. – Genadinik Dec 18 '12 at 03:06
  • @Genadinik It's pretty much certain that `tableLabels` has more objects in it than `topic_array` which is why this is crashing. What about `cellForRowAtIndexPath`? Which array is it using to show the cells? All three of these methods should work off exactly the same data, not different data. – rmaddy Dec 18 '12 at 03:26

0 Answers0