Closed haashem closed 8 years ago
@hashemp206 Best practice is to capture the indexPath
or row
outside of the ASCellNodeBlock and use it inside:
func collectionView(_ collectionView: ASCollectionView, nodeBlockForItemAt indexPath: IndexPath) -> AsyncDisplayKit.ASCellNodeBlock{
let row = indexPath.row;
return {
return ASCellNode(viewControllerBlock: {[unowned self] () -> UIViewController in
let menuViewController: RestMenuViewController2 = UIStoryboard.MainStoryboard.instantiateViewController(withIdentifier: "RestMenuViewController2") as! RestMenuViewController2
// add created menuVC to viewControllers array
self.viewControllers.append(menuViewController)
let category = self.categories[row]
menuViewController.category = category
return menuViewController
}
}
so here it is:
when
ASColelctionView
asynchronously asks for a newASCellNode
, indexPath rapidly gets changed, but stillASCellNodeBlock
is not called, so when I want to access an object in the block I don't get correct object because IndexPath has changed!what's your Idea? should the block hands me the indexPath, or in some way I should persist the sequence of indexPaths?