Force touch UICollectionView inside UITableViewCell

I have a viewController with a Tableview, several TableViewCells and in each TableViewCell, a UICollectionView with several UICollectionViewItems. Each collectionView element has a label and an image. I'm trying to get 3d touch to work, so that the user can drop by pop-force, touching areas of tableCell that do not contain a collection view, to preview and appear in the same view controller, and then be able to do the same thing with one of the images in collections, but viewing and popping into another view controller. I have the first script that works fine, tableCell stays sharp on the screen when it starts clicking and peeking. I'm stuck with this so that it works in the collection view, no matter what I do, only the image view frame remains clear in the first row of the table, no matter which row I actually clicked. Code below:

func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { //get the tableviewCell if let tableCellPath = tableView.indexPathForRow(at: location) { print("tableCellPath=", tableCellPath) if let tableCell = tableView.cellForRow(at: tableCellPath) as? VenueMainTableViewCell { //user tapped on a beer in the collectionview if let collectionView = tableCell.collectionView { let collectionPoint = collectionView.convert(location, from: tableView) if let cvPath = collectionView.indexPathForItem(at: collectionPoint) { let collectionViewCell = collectionView.cellForItem(at: cvPath) as? VenueMainCollectionViewCell let cvFrame = collectionViewCell?.itemLabelImageView.frame let bc = storyboard?.instantiateViewController(withIdentifier: "itemDetail") as! ItemDetailViewController let ven = UTcheckin.sharedInstance.Venues[collectionView.tag] let selectedItem = ven.ItemsAtVenue[(collectionViewCell?.tag)!] bc.item = selectedItem previewingContext.sourceRect = cvFrame! return bc } } } if let tablePath = tableView.indexPathForRow(at: location) { //user tapping on a venue, this works previewingContext.sourceRect = tableView.rectForRow(at: tablePath) let vc = storyboard?.instantiateViewController(withIdentifier: "venueDetail") as! VenueDetailViewController vc.venue = UTcheckin.sharedInstance.Venues[tablePath.row] return vc } return nil } return nil } 

It seems I need to get the rectangle of the image representation of the collection view element, but how can I access it since it is in the table cell? Thanks in advance for any pointers.

+5
source share
1 answer

I think the solution for this is the same as for the UITableView . You must register each cell for preview using the registerForPreviewingWithDelegate method. You must register it with cellForRow .

This should be very helpful for you. Especially The Solution Item:


/ a>

+5
source

Source: https://habr.com/ru/post/1262400/


All Articles