这是我的collectionView cellForItemAtIndexPath方法:
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是一个UIView子类,它返回一个带有棋盘的uiview。
当我运行它时,视图控制器加载时单元格中没有任何内容,并且加载单元格需要太多时间。 有什么方法可以让它变得更好吗?