несколько UICollectionview внутри UItabelview с разделами - swift

По сути, я пытаюсь получить что-то похожее на результат этого:http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell

Тем не менее, я хочу, чтобы 2 collectionViews, 1 в первом разделе и еще один во 2-м разделе

как мне этого добиться? я бью свою голову здесь ... каждый раз, когда я пытаюсь установить делегат и источник данных, он терпит неудачу и говорит, что мне нужно зарегистрировать перо. Также я понятия не имею, как я разделяю представления коллекции в его cellForRowAtIndexPath, как я могу увидеть, какие один загружается? как я могу заставить его загружаться правильно, чтобы в первом разделе был self.genre, а во втором разделе self.radioStat

это ошибка, которую я получаю, когда пытаюсь установить делегат и источник данных во второй раз

** Завершение приложения из-за необработанного исключения «NSInternalInconsistencyException», причина: «не удалось удалить из очереди представление вида: UICollectionElementKindCell с идентификатором CollectionViewCell34 - необходимо зарегистрировать перо или класс для идентификатора или подключить ячейку прототипа в раскадровке» **

tableViewCellCollectionView.swift

import Foundation
import UIKit
let collectionViewCellIdentifier: NSString = "CollectionViewCell"
class tableViewCellCollectionView: UITableViewCell  {

var collectionView: UICollectionView!

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)

    var layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsetsMake(4, 5, 4, 5)
    layout.minimumLineSpacing = 5
    layout.itemSize = CGSizeMake(91, 91)
    layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
    self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
    self.collectionView.registerClass(collectionViewCellTableView.self, forCellWithReuseIdentifier: "CollectionViewCell")
    self.collectionView.registerClass(collectionViewCellTableView.self, forCellWithReuseIdentifier: collectionViewCellIdentifier)
    self.collectionView.backgroundColor = UIColor.lightGrayColor()
    self.collectionView.showsHorizontalScrollIndicator = false
    self.contentView.addSubview(self.collectionView)
    self.layoutMargins = UIEdgeInsetsMake(10, 0, 10, 0)

}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

override func layoutSubviews() {
    super.layoutSubviews()
    let frame = self.contentView.bounds
    self.collectionView.frame = CGRectMake(0, 0.5, frame.size.width, frame.size.height - 1)
}

func setCollectionViewDataSourceDelegate(dataSourceDelegate delegate: protocol<UICollectionViewDelegate,UICollectionViewDataSource>, index: NSInteger) {
    self.collectionView.dataSource = delegate
    self.collectionView.delegate = delegate
    self.collectionView.tag = index
    self.collectionView.reloadData()
}
}

tableViewCellCollectionView34.swift

import Foundation
import UIKit
let collectionViewCellIdentifier34: NSString = "CollectionViewCell34"
class tableViewCellCollectionView2: UITableViewCell  {
var collectionView2: UICollectionView!

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)


    var layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsetsMake(4, 5, 4, 5)
    layout.minimumLineSpacing = 1
    layout.itemSize = CGSizeMake(86, 54)
    layout.scrollDirection = UICollectionViewScrollDirection.Vertical
    self.collectionView2 = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
    self.collectionView2.registerClass(collectionViewCellTableView2.self, forCellWithReuseIdentifier: collectionViewCellIdentifier34)
    self.collectionView2.backgroundColor = UIColor.lightGrayColor()
    self.collectionView2.showsHorizontalScrollIndicator = false
    self.contentView.addSubview(self.collectionView2)
    self.layoutMargins = UIEdgeInsetsMake(10, 0, 10, 0)


}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

override func layoutSubviews() {
    super.layoutSubviews()
    let frame = self.contentView.bounds
    self.collectionView2.frame = CGRectMake(0, 0.5, frame.size.width, frame.size.height - 1)
}

func setCollectionViewDataSourceDelegate2(dataSourceDelegate delegate: protocol<UICollectionViewDelegate,UICollectionViewDataSource>, index: NSInteger) {
    self.collectionView2.dataSource = delegate
    self.collectionView2.delegate = delegate
    self.collectionView2.tag = index
    self.collectionView2.registerClass(collectionViewCellTableView2.self, forCellWithReuseIdentifier: collectionViewCellIdentifier34)
    self.collectionView2.reloadData()
} 

}

Player.swift

   extension Player: UICollectionViewDataSource,UICollectionViewDelegate {


func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return self.radioStat.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

        let cell: collectionViewCellTableView = collectionView.dequeueReusableCellWithReuseIdentifier(reuseCollectionViewCellIdentifier, forIndexPath: indexPath) as collectionViewCellTableView
        var rowData: String = self.genre.objectAtIndex(indexPath.row) as String
        cell.title.text = rowData as String

        let cell2: collectionViewCellTableView2 = collectionView.dequeueReusableCellWithReuseIdentifier(reuseCollectionViewCellIdentifier2, forIndexPath: indexPath) as collectionViewCellTableView2
        let userPost: String  = self.radioStat.objectAtIndex(indexPath.row) as String
        cell2.pinImage.image = UIImage(named: userPost)




    let collectionViewArray = self.sourceArray[collectionView.tag] as NSArray



    return cell
}
extension Player {


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
   var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as UITableViewCell


    if (indexPath.section == 0){
        var cell2: tableViewCellCollectionView = tableView.dequeueReusableCellWithIdentifier(reuseTableViewCellIdentifier, forIndexPath: indexPath) as tableViewCellCollectionView
        return cell2
    }else if (indexPath.section == 1){
        let cell3: tableViewCellCollectionView2 = tableView.dequeueReusableCellWithIdentifier(reuseTableViewCellIdentifier2, forIndexPath: indexPath) as tableViewCellCollectionView2
        return cell3
    }
    return cell

}

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    if (indexPath.section == 0){
    if let collectionCell: tableViewCellCollectionView = cell as? tableViewCellCollectionView{
    collectionCell.setCollectionViewDataSourceDelegate(dataSourceDelegate: self, index: indexPath.row)
    }
    }
    if (indexPath.section == 1){
    if let collectionCell2: tableViewCellCollectionView2 = cell as? tableViewCellCollectionView2{
        collectionCell2.setCollectionViewDataSourceDelegate2(dataSourceDelegate: self, index: indexPath.row)
    }
    }


    }


func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    if (indexPath.section == 0){
        return 50
    }

    if (indexPath.section == 1){
        return 450
    }else {
        return 100
    }

}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
            return sourceArray.count
        }
}

Ответы на вопрос(1)

Ваш ответ на вопрос