I have been reading around but I cannot fix this weird behavior.
I am using a UIContextMenu
in a Mac Catalyst app. Whenever the user right clicks in a tableViewCell
I need to get the datasource object for that row.
I have implemented the following:
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
let indexPath = tableView.indexPathForRow(at: location)
print("location:", location)
let object = ds[indexPath.row]
//.... rest of the code
}
The above always prints that the indexPath is (0, 0)
, even though I have more cells.
I have tried to convert the location to the tableView
with the following:
let locationInTableView = view.convert(location, to: tableView)
Then use it with:
let indexPath = tableView.indexPathForRow(at: locationInTableView)
But the result is always the same.
Am I doing something wrong here?