【发布时间】:2017-12-14 12:41:29
【问题描述】:
我正在尝试实现水平和垂直滚动都可以工作的视图。为此,我采用了 Main Collection 视图。我把它的布局设置为水平的。在该集合视图的单元格中,我采用了另一个集合视图,我将其布局视为垂直。当我尝试运行它时,它会给出错误
2017-12-14 19:02:09.518532+0530 FoodFuels[16834:484154] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/abc/Library/Developer/CoreSimulator/Devices/EA4BBA47-DB91-4C91-B332-D3D6BD5C8698/data/Containers/Bundle/Application/1E7716C3-08F8-4AC6-8106-B961EB8E1076/FoodFuels.app> (loaded)' with name 'MainCollectionViewCell''
*** First throw call stack:
(
0 CoreFoundation 0x000000010bd241ab __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010b3c1f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010bd98cb5 +[NSException raise:format:] + 197
3 UIKit 0x000000010cd3b11c -[UINib instantiateWithOwner:options:] + 501
4 UIKit 0x000000010d38eb2b -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 998
5 UIKit 0x000000010d38f39b -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169
6 FoodFuels 0x0000000109f3c5c8 -[RecipesViewController collectionView:cellForItemAtIndexPath:] + 1096
7 UIKit 0x000000010d3785ea -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 290
8 UIKit 0x000000010d3784c2 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 35
9 UIKit 0x000000010d37d9df -[UICollectionView _updateVisibleCellsNow:] + 4775
10 UIKit 0x000000010d3838d4 -[UICollectionView layoutSubviews] + 364
11 UIKit 0x000000010c9816f5 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1439
12 QuartzCore 0x000000010a9e03ee -[CALayer layoutSublayers] + 153
13 QuartzCore 0x000000010a9e44dd _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
14 QuartzCore 0x000000010a96cded _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 365
15 QuartzCore 0x000000010a998704 _ZN2CA11Transaction6commitEv + 500
16 UIKit 0x000000010c8daca3 _afterCACommitHandler + 272
17 CoreFoundation 0x000000010bcc6d37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x000000010bcc6c8e __CFRunLoopDoObservers + 430
19 CoreFoundation 0x000000010bcab254 __CFRunLoopRun + 1572
20 CoreFoundation 0x000000010bcaa9b9 CFRunLoopRunSpecific + 409
21 GraphicsServices 0x000000011238c9c6 GSEventRunModal + 62
22 UIKit 0x000000010c8b05e8 UIApplicationMain + 159
23 FoodFuels 0x0000000109f3e4ff main + 111
24 libdyld.dylib 0x000000010fa0fd81 start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) .
我已经尝试了网上所有可能的解决方案,但还没有找到适合我的情况的解决方案。
代码:
#import "RecipesViewController.h"
#import "DemoNavigationController.h"
#import "NewSideViewController.h"
#import "RecipesCategoriesCollectionViewCell.h"
#import "RecipesTableViewCell.h"
#import "RecipesHorizontalCell.h"
#import "VerticalCollectionViewCell.h"
#import "MainCollectionViewCell.h"
@interface RecipesViewController () <UICollectionViewDataSource,UICollectionViewDelegate> {
NSMutableArray *recipeTypeArray;
RecipesHorizontalCell *cell;
VerticalCollectionViewCell *verticalCell;
MainCollectionViewCell *mainCell;
}
@property (strong, nonatomic) NSMutableArray *images;
@end
@implementation RecipesViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpInitialView];
}
-(void)setUpInitialView{
recipeTypeArray = [[NSMutableArray alloc]initWithObjects:@"ALL",@"PROTEIN VEGGIE",@"FRUIT",@"FAST FUEL",@"CARB",@"VEGETERIAN",@"SEA FOOD",@"CHICKEN", nil];
_images = [@[@"bg-sidebarProfile.jpg"]mutableCopy];
[self.mainCollectionView registerNib:[UINib nibWithNibName:@"MainCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"MainCollectionViewCell"];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return recipeTypeArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if(collectionView == _horizontalCollectionView){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
[cell.recipeTypeBtn setTitle:[recipeTypeArray objectAtIndex:indexPath.row] forState:UIControlStateNormal];
return cell;
}
else {
verticalCell= [collectionView dequeueReusableCellWithReuseIdentifier:@"cvCell" forIndexPath:indexPath];
verticalCell.commentTextView.layer.borderColor = [UIColor blackColor].CGColor;
verticalCell.commentTextView.layer.borderWidth = 0.5;
_verticalCollectionView.pagingEnabled = true;
return verticalCell;
}
// else{
// if(mainCell==nil){
// mainCell= [_mainCollectionView dequeueReusableCellWithReuseIdentifier:@"MainCollectionViewCell" forIndexPath:indexPath];
// }
// return mainCell;
// }
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(collectionView ==_verticalCollectionView){
return collectionView.bounds.size;
}
else{
return CGSizeMake(150, 120);
}
}
@end
【问题讨论】:
-
你能发布你的主要 CollectionView 初始化和它的单元格的 awakeFromNIb
-
我什么都没做,只是注册了笔尖并尝试在 cellforrowatindexpath 数据源方法中返回单元格。
-
为简单起见,尝试将单元格中的collectionView替换为tableView,因为它是垂直的
-
我已经做了横向的事情,只是停留在一个问题上……为此我必须从头开始。
-
问题可能在于加载内部单元格,因此无法加载主单元格
标签: ios objective-c uicollectionview