Search code examples
iosipaduitableviewnslocalizedstringnsrangeexception

Localized App crashes with NSRangeException


I have an iOS app that has been working quite well in two languages – I know added some stuff, already keeping in mind using NSLocalizedString for localization etc. The english version of the app works fine so far, but the second language version crashes right after starting. Why?

One should note that I have not added all NSLocalizedStrings in my localizable.strings file. Furthermore, I have two separate Storyboards for both english an german. Any help would be greatly appreciated!

2014-12-18 18:14:36.083 Coverdale[48297:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0   CoreFoundation                      0x002461e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x020538e5 objc_exception_throw + 44
2   CoreFoundation                      0x001fa8b2 -[__NSArrayI objectAtIndex:] + 210
3   UIKit                               0x0126a35f -[UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 127
4   UIKit                               0x00fe3f34 -[UITableViewController tableView:indentationLevelForRowAtIndexPath:] + 61
5   UIKit                               0x00e012cf __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1786
6   UIKit                               0x00d7581f +[UIView(Animation) performWithoutAnimation:] + 82
7   UIKit                               0x00d75868 +[UIView(Animation) _performWithoutAnimation:] + 40
8   UIKit                               0x00e00bd0 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
9   UIKit                               0x00e0813d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
10  UIKit                               0x00e081f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
11  UIKit                               0x00de9ece -[UITableView _updateVisibleCellsNow:] + 2428
12  UIKit                               0x00dfe6a5 -[UITableView layoutSubviews] + 213
13  UIKit                               0x00d7e964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14  libobjc.A.dylib                     0x0206582b -[NSObject performSelector:withObject:] + 70
15  QuartzCore                          0x007c845a -[CALayer layoutSublayers] + 148
16  QuartzCore                          0x007bc244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17  QuartzCore                          0x007bc0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18  QuartzCore                          0x007227fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19  QuartzCore                          0x00723b85 _ZN2CA11Transaction6commitEv + 393
20  QuartzCore                          0x00724258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21  CoreFoundation                      0x0020e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22  CoreFoundation                      0x0020e2bf __CFRunLoopDoObservers + 399
23  CoreFoundation                      0x001ec254 __CFRunLoopRun + 1076
24  CoreFoundation                      0x001eb9d3 CFRunLoopRunSpecific + 467
25  CoreFoundation                      0x001eb7eb CFRunLoopRunInMode + 123
26  GraphicsServices                    0x0406b5ee GSEventRunModal + 192
27  GraphicsServices                    0x0406b42b GSEventRun + 104
28  UIKit                               0x00d0ff9b UIApplicationMain + 1225
29  Coverdale                           0x0009b95d main + 141
30  libdyld.dylib                       0x028b9701 start + 1
31  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

EDIT

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Error";
if (indexPath.section == 0) {
    if(indexPath.row == 0)
    { /*..*/}
}
return cell;
}

Solution

  • Turns out I needed to implement indentationLevelForRowAtIndexPath and just return 0.