2016-08-24 8 views
1

私のアプリケーションは、バックグラウンドへのアプリケーションと再びフォアグラウンドに戻ってくると崩壊するときに、IMアプリケーションです。 これは、コードの私の部分で、このコードにテーブルビューリフレッシュクラッシュスレッド1:シグナルSIGABRT

-(void)uiAddChatroomMessages:(NSArray*)messages{ 
    NSMutableArray *indexPaths = [[NSMutableArray alloc]init]; 
    int i = (short)self.messageArray.count ; 
    for (RTIMMessage *msg in messages) { 
     [self.messageArray addObject:msg]; 
    } 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; 
    [indexPaths addObject:indexPath]; 
    [self.chatMessageTableView beginUpdates]; 
    [self.chatMessageTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 
    [self.chatMessageTableView endUpdates]; 
    [self.chatMessageTableView reloadData]; 
} 

ファイル名を指定して実行「[self.chatMessageTableView endUpdates]」、それが「スレッド1:信号SIGABRT」つぶすと、プロンプト。

2016年8月24日15:49:18.500 RTIM_iOS_Demo [1834:1326398] で*アサーション 故障 - [のUITableView _endCellAnimationsWithContext:]、 /BuildRoot/Library/Caches/com.apple.xbs/Sources /UIKit/UIKit-3512.60.12/UITableView.m:1716 2016年8月24日15:49:18.590 RTIM_iOS_Demo [1834:1326398] *がキャッチされない例外が原因 アプリ 'NSInternalInconsistencyException'、 理由終了:「無効なアップデートを:セクション0の行数が無効です。更新後の既存のセクション(62) に含まれる 行の数は、その秒に含まれる行の数と等しくなければなりません 更新(57)の前に、挿入または削除された行の数をプラスまたはマイナスして、そのセクション(挿入された1個、削除された0)から をプラスまたはマイナスします。 、0は外に出た)。 ***まずスローコールスタック:(0x18238adb0 0x1819eff80 0x18238ac80 0x182d10154 0x1876e1808 0x100072ccc 0x1000728b0 0x100095244 0x10009468c 0x100077d20 0x100241a7c 0x100241a3c 0x1002474e4 0x182340d50 0x18233ebb8 0x182268c50 0x183b50088 0x187552088 0x1000a5340 0x181e068b8)のlibC++ abi.dylib:タイプNSException

のキャッチされない 除いて終了
+0

** 'insertRowsAtIndexPaths'の直後に' reloadData'を呼び出さないでください。挿入メソッドは、テーブルビューを自動的に再配置します。 – vadian

答えて

0

self.messageArrayにいくつかの新しいオブジェクトを追加しましたが、1行だけ追加しました。にコードを変更します。

-(void)uiAddChatroomMessages:(NSArray*)messages{ 
    NSMutableArray *indexPaths = [NSMutableArray array]; 
    NSUInteger i = self.messageArray.count; 
    for (RTIMMessage *msg in messages) { 
     [self.messageArray addObject:msg]; 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; 
     [indexPaths addObject:indexPath]; 
     i ++; 
    } 

    [self.chatMessageTableView beginUpdates]; 
    [self.chatMessageTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 
    [self.chatMessageTableView endUpdates]; 
    [self.chatMessageTableView reloadData]; 
} 
+0

ありがとうございます! – shycie

0

スタックトレースごとに、インデックスパスが間違っているようです。行のインデックスとして配列数を使用しています。配列数-1で試してみましょう。

0

numberOfRowsInSectionによって返された数字は、新しい期待値と一致する必要があります。あなたは、変更されていない配列の要素の定数またはいくつかを返すかもしれません。

関連する問題