我正在尝试实现水平和垂直滚动都可以工作的视图。为此,我采用了Main Collection视图。我把它的布局设为横向。在该集合视图的单元格中,我采用了另一个集合视图,其布局我采用了垂直。当我试图运行它时会出错
migrate
我已尝试过所有可能的网络解决方案,但还没有解决我的问题。
代码:
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) .
答案 0 :(得分:0)
请参阅CollectionView到CollectionView单元格将是这样的
protocol FlashDealCollectionViewCellDelegate:NSObjectProtocol {
func onFlashDealItemClicked();
}
class FlashDealCollectionViewCell: UICollectionViewCell ,
UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,
UICollectionViewDataSource{
//for handle click event using delegate
weak var delegate: FlashDealCollectionViewCellDelegate?
override func awakeFromNib() {
super.awakeFromNib()
serInnerCollectionView()
}
func serInnerCollectionView() {
flashDealCollectionView.delegate = self
flashDealCollectionView.dataSource = self
flashDealCollectionView.register(UINib(nibName:
"FlashDealItemView", bundle: nil), forCellWithReuseIdentifier:
"flashdealitem")
}
func collectionView(_ collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return 25
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt
indexPath: IndexPath) -> UICollectionViewCell {
let m:FlashDealItemCollectionViewCell =
collectionView.dequeueReusableCell(withReuseIdentifier:
"flashdealitem", for: indexPath) as! FlashDealItemCollectionViewCell
return m;
}
func collectionView(_ collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout, sizeForItemAt
indexPath: IndexPath) -> CGSize {
let width = 80;
return CGSize(width: width+10, height: 100);
}
func collectionView(_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath) {
guard let delegate = delegate else {
return
}
//Handle click event
delegate.onFlashDealItemClicked()
}
答案 1 :(得分:0)
不赞成这样
else{
MainCollectionViewCell*mainCell= [_mainCollectionView dequeueReusableCellWithReuseIdentifier:@"MainCollectionViewCell" forIndexPath:indexPath];
return mainCell;
}