collectionViewCell 的 initWithFrame 方法不触发
网络数据作为 UICollectionView 的数据源的时候,自定义的 UICollectionViewCell 的 initWithFrame 不触发
本地数组作为 UICollectionView 的数据源的时候,自定义的 UICollectionViewCell 的 initWithFrame 触发
// NSArray *arr = @[@"花器", @"茶具", @"禅悟", @"酒局"];
// [self.hotArray addObjectsFromArray:arr];
初始化 UICollectionView
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 20;
layout.minimumInteritemSpacing = 10;
layout.estimatedItemSize = CGSizeMake(20, 60);
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layout];
self.collectionView.backgroundColor = [UIColor orangeColor];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.view addSubview:self.collectionView];
[self.collectionView registerClass:[SearchViewCell class] forCellWithReuseIdentifier:@"identifier"];
[self getHotKeyData];
网络数据获取的方法
- (void)getHotKeyData {
[NetworkingTool postDataWithPath:[MAIN_PATH stringByAppendingString:@"show/show/searchkey"] parameters:nil successBlock:^(NSDictionary *dictionary) {
NSString *status = dictionary[@"status"];
if ([status isEqualToString:@"1"]) {
NSArray *dataArray = dictionary[@"data"];
// NSLog(@"dataCount -- %ld", dataArray.count);
for (NSDictionary *dict in dataArray) {
HotKey *hotKey = [HotKey feedWithDictionary:dict];
[self.hotArray addObject:hotKey];
}
NSLog(@"count -- %ld", self.hotArray.count);
[self.collectionView reloadData];
}
} failureBlock:^(NSString *error) {
NSLog(@"error : %@", error);
}];
}