2017-10-06 108 views
0

我需要能够为我的UICollectionView在Peek和Pop的提交函数中获得indexPath.rowindexPath in viewControllerToCommit函数

func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) { 

    } 

我需要这样做,因为在UICollectionView每一行打开一个不同的视图控制器,需要通过对不同行的信息。有任何想法吗?

回答

0

推荐的方法是要呈现哪个应该已经充满了你UICollectionView的好项目viewControllerToCommit对象:

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) 
}