【发布时间】:2018-06-04 07:30:20
【问题描述】:
我想制作 UICollectionViewCell 的动态大小。
它在 iOS 10 上运行,但应用在 iOS 9 中崩溃。
我尝试了很多解决方案,但没有一个有效。
我想要 iOS 9 上的上述输出
- (void)viewDidLoad {
[super viewDidLoad];
[self.collectionView setContentInset:UIEdgeInsetsMake(8, 8, 8, 8)];
[self.collectionView registerNib:[UINib nibWithNibName:@"CustomeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"CustomeCollectionViewCell"];
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
flowLayout.estimatedItemSize = CGSizeMake(1, 1);
flowLayout.minimumLineSpacing = 8.0f;
flowLayout.minimumInteritemSpacing = 8.0f;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CustomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomeCollectionViewCell" forIndexPath:indexPath];
cell.lblText.text = [self.dataArr objectAtIndex:indexPath.item];
cell.backgroundColor = [UIColor blackColor];
return cell;
}
错误日志
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayM objectAtIndex:]:空数组的索引 0 超出范围”***第一次抛出调用堆栈:(0x2592791b 0x250c2e17 0x2583972b 0x2a6faba7 0x2a6b8adf 0x2a698753 0x2a698d87 0x29f08d57 0x29f06ed3 0x29f01fe9 0x29e9ea73 0x27f36bcd 0x27f32375 0x27f32209 0x27f316d1 0x27f313a5 0x29e95b79 0x258e96c9 0x258e79cd 0x258e7dff 0x25837229 0x25837015 0x26e27ac9 0x29f0b189 0x66f2d 0x254df873)的libc ++ abi.dylib:与类型的未捕获的异常终止NSException
【问题讨论】:
-
请添加错误日志并显示您在哪一行崩溃
-
*** 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array”*** 第一次抛出调用堆栈: (0x2592791b 0x250c2e17 0x2583972b 0x2a6faba7 0x2a6b8adf 0x2a698753 0x2a698d87 0x29f08d57 0x29f06ed3 0x29f01fe9 0x29e9ea73 0x27f36bcd 0x27f32375 0x27f32209 0x27f316d1 0x27f313a5 0x29e95b79 0x258e96c9 0x258e79cd 0x258e7dff 0x25837229 0x25837015 0x26e27ac9 0x29f0b189 0x66f2d 0x254df873)的libc ++ abi.dylib:与类型的未捕获的异常NSException 跨度>终止
-
返回单元格后崩溃
-
你能说明你在哪里初始化
dataArr,你在哪里改变它? -
我在
viewDidLoad方法上看不到它
标签: ios objective-c uicollectionview uicollectionviewcell