Células UICollectionView com imagens dentro do protótipo UITableView

ATUALIZAÇÃO: Solucionei meu problema principal de imagens corretas, não carregando até rolar no collectionView. Adicionei um collectionView.reloadData () ao tableView: cellForRowAtIndexPath. Também fiz algumas alterações para pré-carregar a matriz de sequência, em vez de construí-la enquanto percorria a tabela (tableView: cellForRowAtIndexPath).

Adicionadas as atualizações ao GitHub, se você estiver interessado.
https://github.com/Druiced/OpenDeck

Vou acompanhar assim que descobrir como impedir que o aplicativo falhe quando um valor dinâmico for colocado no retorno (se eu definir isso como 15, o aplicativo não falhará):

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return count(Array(sequenceArray[collectionView.tag])) / 2
}

POST ORIGINAL: pedido de orientação.

Este tutorial me ajudou a perceber que isso deve ter a ver com meu DataSource / Delegate. O autor constrói a célula com addSubview em vez de tirar proveito da célula protótipo do Xcode, que parece uma coisa legal, então estou tentando fazer isso.http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell

Qualquer crítica sobre minha abordagem ou falha em seguir as melhores práticas é bem-vinda.

Cada célula da tabela possui um UICollectionView. Cada célula na exibição de coleção exibe uma imagem na ordem da sequência "Sequência" salva. exemplo: link "ADKDQDJDTD" até AD.png KD.png QD.png JD.png TD.png

Tenho dois problemas que não consigo superar.

numberOfItemsInSection fica esquisito quando o número de cartões é determinado pelo comprimento da matriz (retorne handArray.count / 2). Se eu colocar um número fixo, o aplicativo funcionará, mas não muito liso.Quando a mesa aparece, as cartas corretas não são exibidas até eu rolar para cima e para baixo na mesa. Também parece que os dados de cada CollectionView estão cruzando os caminhos, pois os cartões incorretos aparecem ao rolar para cima e para baixo rapidamente.

Estou quase certo de que isso tem a ver com a configuração da minha fonte de dados.

DeckTableViewController.swift

import UIKit
import Parse

var deviceID: String?
var noRefresh: Bool?
var sequenceArray: Array<Character>?

class DeckTableViewController: UITableViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var handArray: Array<Character>!
var timeLineData:NSMutableArray = NSMutableArray()

override func viewDidLoad() {
    super.viewDidLoad()
    noRefresh = false
    deviceId = UIDevice.currentDevice().identifierForVendor.UUIDString
}

override func viewDidAppear(animated: Bool) {
    if noRefresh == false {
        loadData()
        noRefresh = true
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return timeLineData.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell:DeckTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! DeckTableViewCell

    let deck:PFObject = timeLineData.objectAtIndex(indexPath.row) as! PFObject

    cell.collectionView.dataSource = self
    cell.collectionView.delegate = self

    let sequenceTemp = deck.objectForKey("Sequence") as! String
    handArray = Array(sequenceTemp)
    cell.sequenceId.setTitle(deck.objectId, forState: UIControlState.Normal)
    cell.cardCountLabel.text = "\((count(sequenceTemp)/2))"

    // Date to String Stuff
    var dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "(MM-dd) hh:mm:ss"
    cell.timeLabel.text = dateFormatter.stringFromDate(deck.updatedAt!)

    let layout:UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.itemSize = CGSizeMake(99, 140)
    layout.scrollDirection = UICollectionViewScrollDirection.Horizontal

    cell.collectionView.collectionViewLayout = layout

    return cell
}


func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return handArray.count / 2
}

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

    let cell:TableCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! TableCollectionViewCell
    var bcolor : UIColor = UIColor.orangeColor()
    cell.layer.borderColor = bcolor.CGColor
    cell.layer.borderWidth = 2
    cell.layer.cornerRadius = 3

    var firstLetter: Character!
    var secondLetter: Character!

    //Building card file names from Sequence data
    if (indexPath.row * 2) + 1 <= handArray.count {

        firstLetter = handArray[indexPath.row * 2]
        secondLetter = handArray[indexPath.row * 2 + 1]
        let imageNameString = "\(firstLetter)\(secondLetter).png"
        let front = UIImage(named: imageNameString)
        cell.ImageView.backgroundColor = UIColor.orangeColor()
        cell.ImageView.image = front

    }

    return cell
}

DeckTableViewCell.swift

import UIKit

class DeckTableViewCell: UITableViewCell, UITextViewDelegate {

    @IBOutlet var collectionView: UICollectionView!
    @IBOutlet var sequenceId: UIButton!
    @IBOutlet var timeLabel: UILabel!
    @IBOutlet var cardCountLabel: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }
}

TableCollectionViewCell.swift

importar UIKit

class TableCollectionViewCell: UICollectionViewCell {

    @IBOutlet var ImageView: UIImageView!

}

Para este exemplo, defino (retorne handArray.count / 2) para 10 e carreguei 3 seqüências. O número no centro superior representa o número de cartões para cada linha. Observe que o CollectionView não é atualizado com os cartões certos, ele está captando dados dos outros CollectionViews. Se eu adicionar mais sequências a esse mix, ao rolar para cima e para baixo, as cartas corretas PODERÃO ALGUMAS VEZES, mas imprevisíveis.

Obrigado por todas as sugestões, estou feliz em voltar para a prancheta. Felicidades

questionAnswers(1)

yourAnswerToTheQuestion