在我的卡布奇诺应用程序中,我正在通过 JSON 从 RoR 后端读取数据并将结果放入列表中。当应用程序第一次加载时一切都很好,但是当我编辑一个项目(并将编辑写入数据库)时,刷新项目列表时会产生错误。
错误是CPRangeException: -[_CPJavaScriptArray objectAtIndex:]: index (-1) beyond bounds (3)
。
即使我在未进行任何实际更改的情况下编辑项目,我也会收到此错误。在这种情况下,应用程序接收到的 JSON 字符串保持完全相同,没有添加或删除任何项目,因此不应将数组写入越界。
这是我的代码:
- (void)connection:(CPRURLConnection)connection didReceiveData:(CPString)data
{
if(connection === listConnection)
{
var results = JSON.parse(data) ;
var posts = [Post initFromJSONObjects:results];
[postListView setContent:posts] ;
// My error occurs at the above line
[postListView setSelectionIndexes:[[CPIndexSet alloc] initWithIndex:0]] ;
}
}
我不确定这是否是我的代码错误,或者是否与卡布奇诺框架存在某种不一致。有人知道我能做些什么来解决这个问题吗?
其余代码可以在这里找到