iOS错误“请求无效部分的矩形”是什么意思? [英] What does the iOS error "request for rect of invalid section" mean?

查看:765
本文介绍了iOS错误“请求无效部分的矩形”是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google未发现此错误消息的帖子。我在iOS 5中尝试更新UITableView。虽然确切的代码有点折磨,但这正是我对表和具有表数据的NSMutableArray所做的。调用是通过performSelectorOnMainThread调用从主线程进行的,如下面的代码片段所示。 NSMutableArray节是一个数组数组,每个数组代表一个节,其中这些辅助数组是NSStrings,其中包含表中显示的文本。

Google reveals no posts at all for this error message. I'm getting it in iOS 5 trying to update a UITableView. While the exact code is a bit tortured, this is what I'm doing to the table and the NSMutableArray that has the table data. The calls are made from off of the main thread via performSelectorOnMainThread calls, as indicated in the code snippets below. The NSMutableArray sections is an array of arrays, each representing a section, where these secondary arrays are NSStrings with the text that appears in the table.

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



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



The main code called from another 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];



在上述代码完成后调用:



Called after the above code completes:

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

此次调用endUpdates时发生错误。确切的错误消息是:

The error is occurring on this call to endUpdates. The exact error message is:

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

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

What does this error mean, and what do I need to change to avoid it?

推荐答案

看起来你的代码正在尝试工作表格的一部分不存在。

Looks like your code is trying to work with a section of your table that does not exist.

自NSArra以来ys为零索引, count 的索引值将超出数组的范围。使用 indexSetWithIndex时,你应该从计数中减去一个:这里:

Since NSArrays are zero-indexed, the index value of count will be outside the bounds of the array. You should subtract one from the count when using indexSetWithIndex: here:

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

这篇关于iOS错误“请求无效部分的矩形”是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆