我需要能够在Peek和Pop的提交函数中获取indexPath.row
的{{1}}。
UICollectionView
我需要这样做,因为func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
}
中的每一行都会打开一个不同的视图控制器,需要传递不同行的信息。有什么想法吗?
答案 0 :(得分:1)
推荐的方法是展示viewControllerToCommit
对象,该对象应该已经填充了UICollectionView
的好项:
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = collectionView.indexPathForItem(at: location), let cell = collectionView.cellForRow(at: indexPath) as? YOUR_CELL_CLASS else {
return nil
}
previewingContext.sourceRect = cell.frame
let viewController = YOUR_VIEW_CONTROLLER_CLASS()
viewController.yourObject = cell.yourObject
return viewController
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
navigationController?.pushViewController(viewControllerToCommit, animated: true)
}