I need to popup a menu on a cell in a table view, but to respond to the action by specifying a selector on an object held elsewhere in the app.
I have written the following code in the AppDelegate :
let testMenuItem = UIMenuItem(title: "Test", action: #selector(ValueModelCellPresenter.test(sender:)))
UIMenuController.shared.menuItems = [testMenuItem]
UIMenuController.shared.update()
I am implementing the shouldShowMenuForRowAt, canPerformAction and performAction methods on the table view delegate, as recommended, but the menu is not showing on long press.
I have also implemented :
public override var canBecomeFirstResponder: Bool
{
return true
}
public override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool
{
return action == #selector(ValueModelCellPresenter.test(sender:))
}
@objc public func test(sender: Any)
{
print("here")
}
… in the ValueModelCellPresenter class.
I also tried calling becomeFirstResponder() on the presenter but to no avail.
Can anyone please help me to see what I may have missed?