prepareForSegue collectionView indexPath usando swift
Não encontro nenhum bom exemplo para fazer o que quero usando rapidamente, por isso me permito fazer a pergunta.
Estou usando um collectionView para exibir PFObjects e quero enviar os dados da célula exibidos para um segundo controlador usando prepareForSegue.
Neste ponto, estou lutando para fazer essa parte do código funcionar:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "goto_answerquestion"){
var indexpath : NSIndexPath = self.collectionView.indexPathsForSelectedItems()
}
}
está linha:
var indexpath : NSIndexPath = self.collectionView.indexPathsForSelectedItems()
dispara o seguinte erro:
(UICollectionView, numberOfItemsInSection: Int)-> Int does not have a member named 'indexPathsForSelectedItems'
entre em contato se estiver usando o método errado ou se precisar de dados adicionais para ter uma visão geral apropriada do problema.
RESPONDA
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "segue_identifier"){
// check for / catch all visible cell(s)
for item in self.collectionView!.visibleCells() as [UICollectionViewCell] {
var indexpath : NSIndexPath = self.collectionView.indexPathForCell(item as CollectionViewCell)!
var cell : CollectionViewCell = self.collectionView!.cellForItemAtIndexPath(indexpath) as CollectionViewCell
// Grab related PFObject
var objectData:PFObject = self.questionData.objectAtIndex(indexpath.row) as PFObject
// Pass PFObject to second ViewController
let theDestination = (segue.destinationViewController as answerPageViewController)
theDestination.questionObject = objectData
}
}
}