2017-04-04 6 views
0

私は、の再利用可能なセルを持つtableviewに3Dタッチを実装しようとしました。問題は、実際には、セル内のコレクションビューの正しいセルに焦点を合わせることができないということです。ここに私のコードは次のとおりです。3D Touch UICollectionView insideUITableviewCell

func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { 

    guard let indexPath = tableView.indexPathForRow(at: location) else { return nil } 
    guard let cell = tableView.cellForRow(at: indexPath) as? DiscoveryComponent else { return nil } 
    let collectionView = cell.collectionView 
    print("---- CollectionView \(collectionView)----") 
    let collectionPoint = collectionView.convert(location, from: tableView) 
    guard let collectionIndexPath = collectionView.indexPathForItem(at: collectionPoint) else { return nil } 
    guard let collectionViewCell = collectionView.cellForItem(at: collectionIndexPath) as? DiscoveryProductCell else { return nil } 
    print(collectionIndexPath) 
    print("Collection Cell \(collectionViewCell.productImageView.frame)") 

    previewingContext.sourceRect = collectionViewCell.productImageView.frame 

    return UIViewController() 
} 

問題は、私はtableviewの2列目の3Dタッチを適用しようとすると、その後tableviewの前の行のコレクションビューの最初のセルが注目されています。私のアプローチは間違っていると思います。

もちろん、まだテスト段階にあるので、私はまだ適切なコントローラを返さない。

答えて

0

registerForPreviewing(with:self、sourceView:self.collectionView)

関連する問題