【问题标题】:Localized App crashes with NSRangeException本地化应用程序因 NSRangeException 而崩溃
【发布时间】:2014-12-18 17:21:54
【问题描述】:

我有一个 iOS 应用程序,它在两种语言中运行良好 - 我知道添加了一些东西,已经记住使用 NSLocalizedString 进行本地化等。该应用程序的英文版到目前为止运行良好,但第二语言版本启动后立即崩溃。为什么?

应该注意,我没有在我的 localizable.strings 文件中添加所有 NSLocalizedStrings。此外,我有两个独立的故事板,适用于英语和德语。任何帮助将不胜感激!

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) 

编辑

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

【问题讨论】:

  • 你能在崩溃的地方添加代码块吗?如果您还没有缩小范围,请设置一个异常断点以在它崩溃时捕获
  • 您好,感谢您的回复。不幸的是,异常断点只显示了 main.m: int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class])); }}
  • 你能发布你的表格视图数据源方法吗?如果您实现indentationLevelForRowAtIndexPath,请发布,否则发布您创建单元格的方法,因为看起来您的问题可能存在。
  • 当然。虽然我没有实现indentationLevelForRowAtIndexPath。我没有发布所有内容,但基本上我只是设置了背景图片和tableView的标签。我也在 Storyboard 中创建了一个UITableView,并通过 segues 将它连接到我的其他视图。
  • 这很奇怪。我希望我知道。有时事情只是在没有已知原因的情况下工作。如果您开始遇到更多类似的崩溃,一定要从那里开始

标签: ios ipad uitableview nslocalizedstring nsrangeexception


【解决方案1】:

原来我需要实现indentationLevelForRowAtIndexPath 和return 0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2019-12-26
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多