CollectionViewTableCell

CollectionViewTableCell

我在UITableViewCell中有一个UICollectionView,并且正在从后台线程的解析中检索集合视图的图像。我遇到的麻烦是我无法调用集合视图reloadData,因为我无法设置UICollectionView的属性,因为它位于表视图单元格内。关于如何在UI视图之后重新加载集合视图的数据的任何想法后台线程已完成执行查询?

最佳答案

子类化UITableViewCell并添加方法和对其集合视图的引用。在那里处理您的电话。我假设您已将集合视图设为表视图控制器上的一个属性

例如

CollectionViewTableCell.h:

@interface CollectionViewTableCell : UITableViewCell
@end

CollectionViewTableCell.m:
@interface CollectionViewTableCell ()
    @property (nonatomic, weak) @IBOutlet UICollectionView* collectionView;
@end

@implementation CollectionViewTableCell
-(void) awakeFromNib {
    [self loadData];
}
-(void) loadData {
    // load parse data asynchronously and then call reloadData on your collection view
}

 // make sure to implement delegate/datasource methods for your collection view
@end

请注意,有几种方法可以将图片网址发送到UIImageView,并且图片将从该网址异步加载(例如,AFNetworking具有支持此类别的类别)。

10-08 17:46