2017-06-20 15 views
1

我得到的經典消息「無法出隊類型的觀點:UICollectionElementKindCell與標識符歌曲」。我不知道爲什麼。另一個「無法出隊類型的觀點:UICollectionElementKindCell與標識符歌曲」

***終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「不能出列類型的視圖:UICollectionElementKindCell與標識符歌 - 必須註冊標識的筆尖或類或連接原型細胞在故事板」

我的細胞是自定義類,下面的代碼:

class HACollectionViewCell: UICollectionViewCell { 
    @IBOutlet var title: UILabel! 
    @IBOutlet var band_album: UILabel! 
    @IBOutlet var length: UILabel! 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder:aDecoder) 
     NSLog("I made a new cell!!") 
     //You Code here 
    } 
} 

出口連接(即正確的事情亮起時,我鼠標的指示燈)。單元格佈局位於Main.storyboard中,作爲UICollectionView對象的子元素。

同樣,單元對象本身的「自定義類」中的類設置爲HACollectionViewCell。另外,UICollectionView連接到我的First View Controller文件中的插座。

它失敗的功能:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "song", for: indexPath) as! HACollectionViewCell 
    let song = song_list[indexPath.row] 
    cell.title.text = song.title 
    cell.band_album.text = (song.artist ?? "unknown artist") + (song.albumTitle ?? "unknown album title") 
    cell.length.text = String(song.playbackDuration) 
     return cell 
} 

我檢查,以確保我的重用標識符沒有空格。這完全是「歌曲」。從 「Main.storyboard」:

<collectionReusableView key="sectionFooterView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="song" id="HEQ-RD-L8g" userLabel="Song Cell" customClass="HACollectionViewCell" customModule="Hamper" customModuleProvider="target"> 

順便說一句,我使用的Xcode 8.3.3或在MacOS 10.12.5的Xcode 9(測試版)。兩個程序中都有同樣的錯誤目標是我的iPhone 5s運行iOS 10.3.2。

+0

你在哪裏設計過細胞?它是與Xib還是故事板? –

+0

啊,好問題。我會將答案添加到主文本中。 –

回答

1

<collectionReusableView key="sectionFooterView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="song" id="HEQ-RD-L8g" userLabel="Song Cell" customClass="HACollectionViewCell" customModule="Hamper" customModuleProvider="target">

爲什麼它顯示collectionReusableView?它應該是collectionViewCell是這樣的:

<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="song" id="HEQ-RD-L8g" userLabel="Song Cell" customClass="HACollectionViewCell" customModule="Hamper" customModuleProvider="target">

我認爲你已經使用Collection Reusable View,而不是Collection View Cell

+1

嘿嘿,謝謝,老鷹的眼睛!就是這樣! –

相關問題