gpt4 book ai didi

ios - viewControllerToCommit 函数中的 IndexPath

转载 作者:行者123 更新时间:2023-11-28 06:11:00 26 4
gpt4 key购买 nike

我需要能够在 Peek 和 Pop 的提交函数中为我的 UICollectionView 获取 indexPath.row

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

}

我需要这样做,因为 UICollectionView 中的每一行都会打开一个不同的 View Controller ,并且需要为不同的行传递信息。有什么想法吗?

最佳答案

推荐的方法是呈现 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)
}

关于ios - viewControllerToCommit 函数中的 IndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46604559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com