下記URL動画と全く同じようにUICollectionViewControllerを実装したはずなのですが、
(参考URL:https://www.youtube.com/watch?v=_uOab0HTNmg)
実行すると「libc++abi.dylib: terminating with uncaught exception of type NSException」とエラーが出て止まってしまいます。
何が原因でしょうか…
Swift
1import UIKit 2 3private let reuseIdentifier = "Cell" 4 5class TestCollectionViewController: UICollectionViewController { 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 10 // Uncomment the following line to preserve selection between presentations 11 // self.clearsSelectionOnViewWillAppear = false 12 13 // Register cell classes 14 //self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 15 16 // Do any additional setup after loading the view. 17 } 18 19 /* 20 // MARK: - Navigation 21 22 // In a storyboard-based application, you will often want to do a little preparation before navigation 23 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 24 // Get the new view controller using [segue destinationViewController]. 25 // Pass the selected object to the new view controller. 26 } 27 */ 28 29 // MARK: UICollectionViewDataSource 30 31 override func numberOfSections(in collectionView: UICollectionView) -> Int { 32 // #warning Incomplete implementation, return the number of sections 33 return 1 34 } 35 36 37 override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 38 // #warning Incomplete implementation, return the number of items 39 return 10 40 } 41 42 override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 43 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) 44 45 // Configure the cell 46 47 return cell 48 } 49} 50
エラーはAppDelegate.swiftの下記部分でも表示されています
swift
1import UIKit 2 3@UIApplicationMain 4class AppDelegate: UIResponder, UIApplicationDelegate { //ここで「Thread 1: signal SIGABRT」 5 6 var window: UIWindow? 7 8 9 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 10 // Override point for customization after application launch. 11 return true 12 } 13.....
表示されるエラーは全て記載してください
回答ありがとうございます。
>>表示されるエラーは全て記載してください
失礼しました。エラー全文です↓
2019-05-25 02:50:21.753476+0900 test7[69384:37354035] *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3698.103.12/UICollectionView.m:5417
2019-05-25 02:50:21.757300+0900 test7[69384:37354035] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0 CoreFoundation 0x000000011159b6fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010fbb5ac5 objc_exception_throw + 48
2 CoreFoundation 0x000000011159b482 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010f603927 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 UIKitCore 0x00000001136bf9f9 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 2498
5 UIKitCore 0x00000001136bfc2d -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169
6 test7 0x000000010f2d49df $s5test728TestCollectionViewControllerC010collectionD0_13cellForItemAtSo012UICollectionD4CellCSo0kD0C_10Foundation9IndexPathVtF + 271
7 test7 0x000000010f2d4abb $s5test728TestCollectionViewControllerC010collectionD0_13cellForItemAtSo012UICollectionD4CellCSo0kD0C_10Foundation9IndexPathVtFTo + 155
8 UIKitCore 0x00000001136aa767 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 383
9 UIKitCore 0x00000001136aa5e2 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31
10 UIKitCore 0x00000001136afa8c -[UICollectionView _updateVisibleCellsNow:] + 6120
11 UIKitCore 0x00000001136b4bb6 -[UICollectionView layoutSubviews] + 365
12 UIKitCore 0x00000001143009c1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417
13 QuartzCore 0x0000000115871eae -[CALayer layoutSublayers] + 173
14 QuartzCore 0x0000000115876b88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
15 QuartzCore 0x0000000115882ee4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 72
16 QuartzCore 0x00000001157f23aa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 328
17 QuartzCore 0x0000000115829584 _ZN2CA11Transaction6commitEv + 608
18 UIKitCore 0x0000000113e4bccb __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 128
19 CoreFoundation 0x0000000111502aec __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
20 CoreFoundation 0x00000001115022b0 __CFRunLoopDoBlocks + 336
21 CoreFoundation 0x00000001114fcb34 __CFRunLoopRun + 1252
22 CoreFoundation 0x00000001114fc302 CFRunLoopRunSpecific + 626
23 GraphicsServices 0x00000001195b42fe GSEventRunModal + 65
24 UIKitCore 0x0000000113e32ba2 UIApplicationMain + 140
25 test7 0x000000010f2d5b3b main + 75
26 libdyld.dylib 0x00000001129a3541 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
ありがとうございます!
解決しました(*ᴗˬᴗ)⁾⁾ペコ

回答1件
あなたの回答
tips
プレビュー