Reputation: 125
I have working on framework. Inside framework, i have created UIViewController -> UICollectionView in Xib. Created separated Xib for UICollectionView cell. And registered cell as "TaskCollectionViewCell"
I tried register nib for collectionView it crashing and says Could not load NIB in bundle: NSBundle
here is my code for UIViewController -> UICollectionView:
override public func viewDidLoad() {
super.viewDidLoad()
self.collectionView.delegate = self
self.collectionView.dataSource = self
self.collectionView.register(UINib(nibName: "TaskCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "TaskCollectionViewCell")
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TaskCollectionViewCell", for: indexPath) as! TaskCollectionViewCell
return cell
}
Console error:
2019-11-12 12:08:00.487285+0530 A8FlowSampleApp[35271:1648394] ***
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Could not load NIB in
bundle: 'NSBundle
</Users/A8/Library/Developer/CoreSimulator/Devices/135B1A20-4329-44AA-B2C4-F0426F6BD131/data/Containers/Bundle/Application/79CA4693-3DCF-44A2-A441-36CCBB822894/A8FlowSampleApp.app> (loaded)' with name 'TaskCollectionViewCell''
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c4ee6c +[NSException raise:format:] + 188
3 UIKitCore 0x00007fff474b6553 -[UINib instantiateWithOwner:options:] + 487
4 UIKitCore 0x00007fff4703ec9e -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 874
5 UIKitCore 0x00007fff4703f48d -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 88
6 A8Flow 0x00000001063b42f5 $s6A8Flow6MyTaskC14collectionView_13cellForItemAtSo012UICollectionF4CellCSo0kF0C_10Foundation9IndexPathVtF + 277
7 A8Flow 0x00000001063b4415 $s6A8Flow6MyTaskC14collectionView_13cellForItemAtSo012UICollectionF4CellCSo0kF0C_10Foundation9IndexPathVtFTo + 165
8 UIKitCore 0x00007fff4702980a -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 416
9 UIKitCore 0x00007fff47029664 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31
10 UIKitCore 0x00007fff4702eefc -[UICollectionView _updateVisibleCellsNow:] + 6332
11 UIKitCore 0x00007fff47033f7c -[UICollectionView layoutSubviews] + 351
12 UIKitCore 0x00007fff47d34cfd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
13 QuartzCore 0x00007fff2b138d41 -[CALayer layoutSublayers] + 255
14 QuartzCore 0x00007fff2b13ef33 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
15 UIKitCore 0x00007fff47d1fe75 -[UIView(Hierarchy) layoutBelowIfNeeded] + 980
16 UIKitCore 0x00007fff471369e1 -[UINavigationController _layoutViewController:] + 1465
17 UIKitCore 0x00007fff4712fa92 -[UINavigationController _layoutTopViewControllerLookForNested:] + 589
18 UIKitCore 0x00007fff4712dc32 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 750
19 UIKitCore 0x00007fff47ce95d4 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 410
20 UIKitCore 0x00007fff47ce98a6 -[UINavigationTransitionView _cleanupTransition] + 623
21 UIKitCore 0x00007fff47d2917f +[UIView(UIViewAnimationWithBlocks) conditionallyAnimate:withAnimation:layout:completion:] + 107
22 UIKitCore 0x00007fff47ce9189 -[UINavigationTransitionView transition:fromView:toView:] + 2414
23 UIKitCore 0x00007fff471378c6 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2758
24 UIKitCore 0x00007fff47137d56 -[UINavigationController _startDeferredTransitionIfNeeded:] + 868
25 UIKitCore 0x00007fff471390c1 -[UINavigationController __viewWillLayoutSubviews] + 150
26 UIKitCore 0x00007fff47119ef7 -[UILayoutContainerView layoutSubviews] + 217
27 UIKitCore 0x00007fff47d34cfd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
28 QuartzCore 0x00007fff2b138d41 -[CALayer layoutSublayers] + 255
29 QuartzCore 0x00007fff2b13ef33 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
30 QuartzCore 0x00007fff2b14a86a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
31 QuartzCore 0x00007fff2b0917c8 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
32 QuartzCore 0x00007fff2b0c6ad1 _ZN2CA11Transaction6commitEv + 643
33 UIKitCore 0x00007fff47867481 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
34 CoreFoundation 0x00007fff23bb204c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
35 CoreFoundation 0x00007fff23bb17b8 __CFRunLoopDoBlocks + 312
36 CoreFoundation 0x00007fff23bac644 __CFRunLoopRun + 1284
37 CoreFoundation 0x00007fff23babe16
CFRunLoopRunSpecific + 438
38 GraphicsServices 0x00007fff38438bb0
GSEventRunModal + 65
39 UIKitCore 0x00007fff4784fb68
UIApplicationMain + 1621
40 A8FlowSampleApp 0x0000000105cba6bb main + 75
41 libdyld.dylib 0x00007fff51a1dc25 start + 1
42 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Upvotes: 0
Views: 12016
Reputation: 719
Try not to use NIB. For example if you want to use RXSwift together with a tableview do it like this:
stationsTableView.register(FavoriteTableViewCell.self, forCellReuseIdentifier: "FavoriteCellId")
First is our Cell as a class and second name written in the Identifier
Upvotes: -3
Reputation: 125
fixed issue, after adding bundle, crash stoped..
self.collectionView.register(UINib(nibName: "TaskCollectionViewCell", bundle: Bundle(for: TaskCollectionViewCell.self)), forCellWithReuseIdentifier: "TaskCollectionViewCell")
Upvotes: 5