2016-11-15 14 views
-1

探しクラッシュ:ここviewForSupplementaryElementOfKindアプリは、私はXcodeの8.2を使用して、次のエラーを取得しています(私は要求していないよ)UICollectionElementKindSectionFooter

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindSectionFooter with identifier Header - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

は、問題の原因の関数である:

override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 
    return collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Header", for: indexPath) 
} 

最初はUICollectionElementKindSectionHeaderを見つけるのに問題がありましたが、実際にはInterface Builderでアクティブ化していないため、奇妙なフッタービューに固執しているようです:

Image of IB

補足(回収、再利用可能なビュー)のために再利用識別子は、機能の文字列にマッチします。私は無駄にシミュレータからアプリを削除しようとしました。私は別のニブや何かを普通のものから使いません。

私はこれまでに問題なく、これがXcodeのバグか、どこかに迷ってしまったのかどうかは分かりませんでした。

ご協力いただきありがとうございます。ありがとう。

更新私はviewDidLoadメソッドに以下を追加しようとした回答やコメントへ

ありがとう:

Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewC‌​ategory:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UI‌​Kit-3600.5.2/UIColle‌​ctionView.m:4922

:追加のエラーを求めるメッセージが表示

self.collectionView?.register(UINib(nibName:"Header", bundle: Bundle.main), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier:"Header") 

解決済み

大変申し訳ございません。それは私の愚かな見落としだった。私が実装することを意図した場合

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize { 

:すべての混乱から茎どこ

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { 

基本的に、それはだ @mattは私が間違った方法を実装だろうと指摘しました。

わたしを無視してください。再度、感謝します。

+0

あなたは '' 'レジスタ呼んでいる(_:forSupplementaryViewOfKind:withReuseIdentifier:)' ''? –

+0

@EricKenny no。私はすべきですか? –

+0

はい、 '' '' viewDidLoad''' https://developer.apple.com/reference/uikit/uicollectionview/1618101-register –

答えて

2

にペン先を登録する必要があります。フッターはありません。

はまた、あなたは

self.collectionView?.register(UINib(nibName:"Header", bundle: Bundle.main), 
    forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, 
    withReuseIdentifier:"Header") 

は、その行を削除しますと述べています。ストーリーボードからオブジェクトを取得しているときに登録してはいけません。また、「ヘッダー」という名前のペン先がありません。

アプリはクラッシュすることなく起動します。

+0

私はばかです。もう一度おねがいします@matt –

1

まず、あなたはその方法を削除

func collectionView(_ collectionView: UICollectionView, 
    layout collectionViewLayout: UICollectionViewLayout, 
    referenceSizeForFooterInSection section: Int) -> CGSize { 

を実装しているviewDidLoad()

self.collectionView?.register(UINib(nibName:"Header", bundle: Bundle.main), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier:"Header") 
+0

ありがとうございます。私はこれを追加して、今や追加のエラーが発生しています: 'Assertion failure in - [UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:]、/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit- 3600.5.2/UICollectionView.m:4922' –

+0

しかし、最初のエラーがIBで選択されていなくてもフッタービューを参照しているのは奇妙なことではありませんか? –

0

ルートレベルに別のビューが存在することを確認することをお勧めします。

enter image description here

関連する問題