I have entered the code and the “Delete” button does not appear. In the compiler the machine recognized a single Tap has occured but nothing happens. What I am doing wrong?
func tap(_ gestureRecognizer: UIGestureRecognizer){
print("Recognized a tap")
let point = gestureRecognizer.location(in: self)
selectedLineIndex = indexOfLine(at: point)
// Grab the menu controller
let menu = UIMenuController.shared
if selectedLineIndex != nil {
//Make DrawView the target of menu item action messages
becomeFirstResponder()
//Create a new "Delete" UIMenuItem
let deleteItem = UIMenuItem(title: "Delete",action: #selector(DrawView.deleteLine(_:)))
menu.menuItems = [deleteItem]
//Tell the menu where it should come from and show it
let targetRect = CGRect(x: point.x, y: point.y, width: 2, height: 2)
menu.setTargetRect(targetRect, in: self)
menu.setMenuVisible(true, animated: true)
}else {
//Hide the menu if no line is selected
menu.setMenuVisible(false, animated: true)
}
setNeedsDisplay()
}
override var canBecomeFirstResponder: Bool {
return true
}
func deleteLine(_ sender: UIMenuController) {
//Remove the selected line from the list of finishedLines
if let index = selectedLineIndex {
finishedLines.remove(at: index)
selectedLineIndex = nil
//Redraw everything
setNeedsDisplay()
}
}