1

I am implementing UIContextMenu in my App. It runs very well. Only one problem, once context menu has appeared and disappeared, tableView delegate didSelectRowAt indexPath does not work on first tap, but works on second tap. I can't seem to find what is causing this. It runs fine in Default Mail app in iPhone. Thus, I think there is something that I might be missing. Help me out. Response is appreciated.

What I have already tried is reloading tableView. Also could not find anything helpful in the docs.

@available(iOS 13.0, *)
    func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
        if indexPath.section == 0 {
            let contextMenuConfiguration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (menuElements) -> UIMenu? in
                let edit = UIAction(title: "Edit", image: UIImage.placeholderIcon) { (action) in
                    print("Edit")
                    self.editInvoice(at: indexPath)
                }
                let preview = UIAction(title: "Preview", image: UIImage.placeholderIcon) { (action) in
                    print("Preview")
                }
                let send = UIAction(title: "Send", image: UIImage.placeholderIcon) { (action) in
                    print("Send")
                }
                let share = UIAction(title: "Share", image: UIImage.placeholderIcon) { (action) in
                    print("Share")
                }
                return UIMenu(title: "", image: UIImage.invoiceIcon, identifier: nil, options: UIMenu.Options.displayInline, children: [edit, preview, send])
            }
            return contextMenuConfiguration
        }
        return nil
    }

This is the tableView delegate I implemented. Every thing works fine. All I want is that did select delegate runs on first tap after context menu disappears.

Kamran
  • 14,987
  • 4
  • 33
  • 51
  • 1
    Found it! It was not working because tableView scroll was disabled. As soon as I enabled it, it started working. So this worked for me. :-) – Shubham Singh Jan 22 '20 at 13:00

0 Answers0