1

毎回発生するわけではありませんが、ランダムに insertRowsAtIndexPaths: テーブルビュー endUpdates でアプリがクラッシュします。これがコードです。

NSURLRequest *request1 = [NSURLRequest requestWithURL:url1];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request1 success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    dispatch_async(dispatch_get_main_queue(), ^{
        self.contentArray = [NSMutableArray arrayWithArray:JSON];

        NSMutableArray *indexArray = [NSMutableArray array];
        [self.contentArray enumerateObjectsUsingBlock:^(id anObject, NSUInteger idx, BOOL *stop) {
            [indexArray addObject:[NSIndexPath indexPathForRow:idx inSection:0]];
        }];

        [self.mainTable beginUpdates];
        [self.mainTable insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.mainTable endUpdates];

        self.mainTable.tableFooterView = [self buildLoadingView];
        self.mainTable.contentInset = UIEdgeInsetsMake(64.0, 0.0, 80.0, 0.0);
    });
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
    NSLog(@"%@", JSON);
}];
[operation start];

どんな助けでも大歓迎です!前もって感謝します!

4

1 に答える 1