collectionViewCell 的 initWithFrame 方法不触发

sakjdhk 2017-03-15 08:20:20
网络数据作为 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);
}];
}
...全文
287 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
如果是本地数据走,网络数据不走,那肯定initWithFrame方法是走的。 只能说是协议方法有问题, 要么就是cell有问题,要么就是数组压根没值。
sakjdhk 2017-03-16
  • 打赏
  • 举报
回复
引用 1 楼 superior_yong 的回复:
你是如何确定initWithFrame不触发的?
在 initWithFrame 加上断点,运行的时候并没有打断,所以判断出没有触发
忘丿殇 2017-03-16
  • 打赏
  • 举报
回复
你是如何确定initWithFrame不触发的?

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧