2016-11-22 4 views
0

このチュートリアルに従ってください。だから個人的なイニシアティブはここで取られません。私は、このビューにセグエしようとすると、したがって、おそらくこのエラーを生成する:あなたはUICollectionViewCellCollectionViewControllerに変換しようとしているNSUnknownKeyException UICollectionView

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("memory_image_1", forIndexPath: indexPath) as! CollectionViewController 

return cell 

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Certi.MemoriesView 0x7fb613f3c8d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imageCollectionView.' 

*** First throw call stack: 
(
    0 CoreFoundation      0x000000010ee6ae65 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x000000010f2c7deb objc_exception_throw + 48 
    2 CoreFoundation      0x000000010ee6aaa9 -[NSException raise] + 9 
    3 Foundation       0x000000010cfb29bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 
    4 UIKit        0x000000010d98c320 -[UIViewController setValue:forKey:] + 88 
    5 UIKit        0x000000010dbbaf41 -[UIRuntimeOutletConnection connect] + 109 
    6 CoreFoundation      0x000000010edab4a0 -[NSArray makeObjectsPerformSelector:] + 224 
    7 UIKit        0x000000010dbb9924 -[UINib instantiateWithOwner:options:] + 1864 
    8 UIKit        0x000000010d992eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381 
    9 UIKit        0x000000010d993816 -[UIViewController loadView] + 178 
    10 UIKit        0x000000010d993b74 -[UIViewController loadViewIfRequired] + 138 
    11 UIKit        0x000000010d999f4f -[UIViewController __viewWillAppear:] + 120 
    12 UIKit        0x000000010d9c9e44 -[UINavigationController _startCustomTransition:] + 1203 
    13 UIKit        0x000000010d9da23f -[UINavigationController _startDeferredTransitionIfNeeded:] + 712 
    14 UIKit        0x000000010d9db3af -[UINavigationController __viewWillLayoutSubviews] + 57 
    15 UIKit        0x000000010db81ff7 -[UILayoutContainerView layoutSubviews] + 248 
    16 UIKit        0x000000010d8b44a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703 
    17 QuartzCore       0x000000011101459a -[CALayer layoutSublayers] + 146 
    18 QuartzCore       0x0000000111008e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 
    19 QuartzCore       0x0000000111008cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 
    20 QuartzCore       0x0000000110ffd475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 
    21 QuartzCore       0x000000011102ac0a _ZN2CA11Transaction6commitEv + 486 
    22 UIKit        0x000000010d7f7f7c _UIApplicationHandleEventQueue + 7329 
    23 CoreFoundation      0x000000010ed96a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    24 CoreFoundation      0x000000010ed8c95c __CFRunLoopDoSources0 + 556 
    25 CoreFoundation      0x000000010ed8be13 __CFRunLoopRun + 867 
    26 CoreFoundation      0x000000010ed8b828 CFRunLoopRunSpecific + 488 
    27 GraphicsServices     0x00000001115d7ad2 GSEventRunModal + 161 
    28 UIKit        0x000000010d7fd610 UIApplicationMain + 171 
    29 Certi        0x000000010b92c1fd main + 109 
    30 libdyld.dylib      0x000000010fde392d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
+1

imageCollectionViewにコード内の210本のライン 'セル= collectionView.dequeueReusableCellWithReuseIdentifierてみましょう( "memory_image_1を"、forIndexPath:indexPath)など! CollectionViewController'は正しく表示されません...セルをデキューして、CollectionViewController'にキャストを強制しています..... – EvilGeniusJamie

+0

@EvilGeniusJamie私はこれを実際に実装する上で、適切なチュートリアルもドキュメントも見つけられませんでした。だから、これは私が見たチュートリアルの推測でした。それだけを削除することをお勧めしますか?どういうわけかそれを変える?機能自体は私が意味している。 – Benni

+2

'cell = collectionView.dequeueReusableCellWithReuseIdentifier(" memory_image_1 "、forIndexPath:indexPath)を!UICollectionViewCell' あなたのセルにカスタムクラスを使用していて、この時点でそれを必要としている場合を除き、このラインをコメント – PrafulD

答えて

1

IBOutletimageCollectionViewからimages_collectionに名前を変更したと思われますが、ストーリーボードではこれを更新しませんでした。

は、この問題を解決するには、次の

  • imageCollectionViewボタン "x" は少しをクリックしてMemories Viewへのリンクを削除
  • ストーリーボード

  • 作成あなたのクリックからドラッグして新しいリンクを作成する

ストーリーボード
+0

これはエラーを取り除きました、ありがとう!私は他の答えも考慮に入れていますが、この回答が問題の問題を実際に解決して以来、私はそれを正しいものとしてマークします。 – Benni

1

この機能は問題です。その行の最後に簡単に変更してください:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("memory_image_1", forIndexPath: indexPath) as! UICollectionViewCell 
// see below 
return cell 

でも空白のセルが表示されます。私がコメント\\ see belowを追加したところで、cellの値を更新して、この行に表示される内容を選択する必要があります。複数のセクションを使用している場合は、行はindexPath.rowindexPath.sectionから決定できます。

また、デフォルトのもの以外のビューを扱うカスタムクラスを使用している場合は、UICollectionViewControllerではなく、UICollectionViewControllerの代わりにcellをそのカスタムクラスにキャストする必要があります。まだチュートリアルを見て、これはあなたがまだ試みようとしているものではありません。

質問に私のコメントで述べたように、チュートリアルhttps://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-started - とこのサイトの他のチュートリアルは、初心者の方には非常に良いものです。

+0

非常に丁寧な説明をありがとう! – Benni

関連する問題