iOS错误“无效部分请求”是什么意思?

Google根本没有显示这条错误消息。 我得到它在iOS 5尝试更新UITableView。 虽然确切的代码是有点折磨,这就是我正在做的表和NSMutableArray具有表数据。 这些调用是通过执行performSelectorOnMainThread调用从主线程进行的,如下面的代码片段所示。 NSMutableArray节是一个数组数组,每个数组表示一个节,其中这些辅助数组是NSString,其中的文本出现在表中。

从closures的主线程:

[table performSelectorOnMainThread: @selector(beginUpdates) withObject: nil waitUntilDone: YES]; 

从另一个performSelectorOnMainThread调用的主代码:

 // Make sure the requested section exists. if (sections == nil) sections = [[NSMutableArray alloc] init]; while (section >= [sections count]) { NSMutableArray *newArray = [[NSMutableArray alloc] init]; [sections addObject: newArray]; [table insertSections: [NSIndexSet indexSetWithIndex: [sections count]] withRowAnimation: UITableViewRowAnimationNone]; } // Insert the new row in the section. NSMutableArray *rowArray = [sections objectAtIndex: section]; if (row > [rowArray count]) row = [rowArray count]; [rowArray insertObject: cellString atIndex: row]; [table insertRowsAtIndexPaths: [NSArray arrayWithObject: [NSIndexPath indexPathForRow: row inSection: section]] withRowAnimation: UITableViewRowAnimationNone]; 

上面的代码完成后调用:

 [table performSelectorOnMainThread: @selector(endUpdates) withObject: nil waitUntilDone: YES]; 

这个错误发生在endUpdates的这个调用中。 确切的错误信息是:

 2012-01-04 14:28:10.951 myApp[2183:fb03] *** Assertion failure in -[UITableViewRowData rectForSection:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableViewRowData.m:1449 2012-01-04 14:28:10.953 myApp[2183:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect of invalid section (1)' *** First throw call stack: (0x1833052 0x1d94d0a 0x17dba78 0x11472db 0x99c832 0xa1b93b 0xa1b886 0xa1b451 0xa28134 0x8458e1 0x842602 0x84d211 0x84d23f 0x1834e72 0x10d69ef 0x180797f 0x176ab73 0x176a454 0x1769db4 0x1769ccb 0x33b6879 0x33b693e 0x7bea9b 0x1fad 0x1f25) terminate called throwing an exception 

这个错误是什么意思,我需要改变以避免它?

看起来你的代码正在试图处理你的表中不存在的部分。

由于NSArrays是零索引, count的索引值将超出数组的范围。 当使用indexSetWithIndex:时,您应该从计数中减去一个indexSetWithIndex: here:

 [table insertSections: [NSIndexSet indexSetWithIndex: [sections count]-1] withRowAnimation: UITableViewRowAnimationNone]; 

作为回答发帖,以防万一发生在别人身上。

我发现这个问题看着jonkroll的答案,但在我的情况下,这是因为我调用了同样的方法两次 ,该方法从表视图中删除了一行。

留下这里以及一个单独的可能的原因。

如果您尝试删除moveRowAtIndexPath:方法中的行,您将得到相同的崩溃。 你必须等到它完成。