Collection View Cell Loading time

255 views Asked by At

This my collectionView cellForItemAtIndexPath method:

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{

            ChessBoard *boardView = [[ChessBoard alloc] initWithFrame:CGRectMake(0, cell.frame.size.height - cell.frame.size.width, cell.frame.size.width, cell.frame.size.width)];

            boardView.fenString = self.fenArray[indexPath.item];

            [boardView.highlightBoxes addObject:self.lastMoveFromSqiArray[indexPath.item]];
            [boardView.highlightBoxes addObject:self.lastMoveToSqiArray[indexPath.item]];

            NSLog(@"from %@, to %@", self.lastMoveFromSqiArray[indexPath.item], self.lastMoveToSqiArray[indexPath.item]);
            boardView.showCoordinates = NO;
            [boardView baseInit];

            //main thread
            dispatch_async(dispatch_get_main_queue(), ^{

                [cell addSubview:boardView];
            });

        });


        cell.layer.shouldRasterize = YES;
        cell.layer.rasterizationScale = [UIScreen mainScreen].scale;

        return cell;

ChessBoard is a UIView subclass which returns a uiview with chessboard drawn in it.

When I run this, the view controller is loaded without any content in cells and it takes too much time to load cells. Is there any way i can make it better ?

0

There are 0 answers