UITableViewに自作のカスタムセルを追加したいのですが、セルを作成する際に落ちてしまいます。
Swift カスタムセルを再利用したtableViewの作り方 [初級向け]このサイトを参考にしました。
error
12018-11-15 23:30:49.205810+0900 CustomCell[15445:787106] -[UIImageView _isResizable]: unrecognized selector sent to instance 0x7fc73fd09bc0 22018-11-15 23:30:49.218314+0900 CustomCell[15445:787106] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView _isResizable]: unrecognized selector sent to instance 0x7fc73fd09bc0' 3*** First throw call stack: 4( 5 0 CoreFoundation 0x000000010fde91bb __exceptionPreprocess + 331 6 1 libobjc.A.dylib 0x000000010de03735 objc_exception_throw + 48 7 2 CoreFoundation 0x000000010fe07f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 8 3 UIKitCore 0x00000001142bab4a -[UIResponder doesNotRecognizeSelector:] + 287 9 4 CoreFoundation 0x000000010fdeded6 ___forwarding___ + 1446 10 5 CoreFoundation 0x000000010fdefda8 _CF_forwarding_prep_0 + 120 11 6 UIKitCore 0x000000011472ac10 -[UIImageView(Pretiling) _updatePretiledImageCacheForImage:] + 78 12 7 UIKitCore 0x00000001147298b6 -[UIImageView _updateImageViewForOldImage:newImage:] + 366 13 8 UIKitCore 0x00000001147247f6 -[UIImageView setImage:] + 369 14 9 UIKitCore 0x000000011445ce7e -[UITableViewCell setImage:] + 79 15 10 Foundation 0x000000010d82ede4 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292 16 11 UIKitCore 0x0000000114775fae -[UIView(CALayerDelegate) setValue:forKey:] + 172 17 12 UIKitCore 0x0000000113efc573 -[UIRuntimeOutletConnection connect] + 109 18 13 CoreFoundation 0x000000010fdd4cfd -[NSArray makeObjectsPerformSelector:] + 317 19 14 UIKitCore 0x0000000113ef92b9 -[UINib instantiateWithOwner:options:] + 1814 20 15 UIKitCore 0x00000001144b4dea -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 611 21 16 CustomCell 0x000000010d4cc971 $S10CustomCell14ViewControllerC05tableC0_12cellForRowAtSo07UITablecB0CSo0jC0C_10Foundation9IndexPathVtF + 273 22 17 CustomCell 0x000000010d4ccd4c $S10CustomCell14ViewControllerC05tableC0_12cellForRowAtSo07UITablecB0CSo0jC0C_10Foundation9IndexPathVtFTo + 108 23 18 UIKitCore 0x00000001144d066e -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 771 24 19 UIKitCore 0x00000001144d0bfb -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 73 25 20 UIKitCore 0x0000000114497c36 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2863 26 21 UIKitCore 0x00000001144b88ee -[UITableView layoutSubviews] + 165 27 22 UIKitCore 0x0000000114776795 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1441 28 23 QuartzCore 0x0000000111f4db19 -[CALayer layoutSublayers] + 175 29 24 QuartzCore 0x0000000111f529d3 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395 30 25 QuartzCore 0x0000000111ecb7ca _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 342 31 26 QuartzCore 0x0000000111f0297e _ZN2CA11Transaction6commitEv + 576 32 27 UIKitCore 0x00000001142a72d0 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 139 33 28 CoreFoundation 0x000000010fd4e62c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 34 29 CoreFoundation 0x000000010fd4dde0 __CFRunLoopDoBlocks + 336 35 30 CoreFoundation 0x000000010fd48654 __CFRunLoopRun + 1284 36 31 CoreFoundation 0x000000010fd47e11 CFRunLoopRunSpecific + 625 37 32 GraphicsServices 0x0000000117fe91dd GSEventRunModal + 62 38 33 UIKitCore 0x000000011428c81d UIApplicationMain + 140 39 34 CustomCell 0x000000010d4cfbe7 main + 71 40 35 libdyld.dylib 0x0000000111282575 start + 1 41 36 ??? 0x0000000000000001 0x0 + 1 42) 43libc++abi.dylib: terminating with uncaught exception of type NSException 44(lldb)
viewControllerで設定しているregisterを設定して,呼び出しもサイトと同じような形になっていると思います。
落ちてしまうのはcellを宣言している部分です
ViewController
1 override func viewDidLoad() { 2 ... 3 table.register(UINib(nibName: "CutsomCell", bundle: nil), forCellReuseIdentifier: "uniqueCell") 4 } 5 6 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 7 let cell = table.dequeueReusableCell(withIdentifier: "uniqueCell") as! CutsomCell 8 let image = UIImage(named: "img") 9 cell.setData(cellImage: image!, Title: "テスト") 10 11 return cell 12 }
カスタムセルのクラスはこのようになっています。
Swift
1class CutsomCell: UITableViewCell { 2 @IBOutlet weak var cellImage: UIImageView! 3 @IBOutlet weak var cellText: UITextView! 4 5 func setData(cellImage img: UIImage, Title txt: String){ 6 self.cellImage.image = img 7 self.cellText.text = txt 8 } 9}
xibファイルはこのような形でUIImageViewとTextViewを配置しています
xibファイルのクラスはCustomCellを指定できています。
NSInvalidArgumentExceptionこのエラーログで検索してみたところ、xibのオブジェクトの定義名のミスというものができたのですが、同じになっていると思うので何が原因かわかりません。
追記
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/18 02:49
2018/11/18 06:57
2018/11/18 08:14
2018/11/18 08:17