0

私はデータソースであるC++オブジェクトを持つUITableViewを持っているので、NSArrayの種類はありません。既存のリストの最後に行を挿入しようとするとクラッシュします

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]

[tableView endUpdates] でクラッシュします。ただし、実装には NSArray や objectAtIndex を呼び出すコードはありません。なぜクラッシュするのかわかりません。

単一のセクションしかなく、常に新しい行をセクション 0 の最後に追加します。返される行数は正しいため、完全に同期されます。

私が見るログでは、[tableView endUpdates] は numberOfRowsInSection を呼び出し、前のカウントに 1 を加えたカウントを正しく返します。ただし、 cellForRowAtIndexPath を再度呼び出すことはなく、[tableView endUpdates] を通過できません。

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"...");

    ........


    NSArray *insertIndexPaths = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:oldCount + i inSection:[indexPath section]], nil];

    NSLog(@"Insert: %d %d %d", i, (int) oldCount, (int) newCount);

    [tableView beginUpdates];        
    [tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone];                
    [tableView endUpdates];

}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int i = _reader->allRead() ? _reader->getWindowCount() : _reader->getWindowCount() + 30;    
    return i;
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{   
    return 1;
//    return __results__ ? 1 : 0;
}
4

2 に答える 2

0

テーブルビューを更新しているので、データソースも更新する必要があります。あなたのコードではデータソースの更新方法が表示されていないので、それを考慮する必要があると思います。

于 2012-04-07T11:50:05.300 に答える