【发布时间】:2017-08-08 09:53:28
【问题描述】:
我的代码很简单,就是想创建一个流式布局UIColloctionView
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 7;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [UICollectionViewCell new];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(SCREEN_WIDTH / 2 - 5, 160);
}
这是错误
*** -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] 中的断言失败, /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.9.1/UICollectionView.m:2115
【问题讨论】:
-
你正在使用storyboard或xib??
-
@ShabbirAhmad 两者都没有,只有代码
-
只需将单元格从队列中取出: UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
标签: ios cocoa-touch uicollectionview