I've a UITableView
and I'd like to make an UIAlertView
to appears on a UILongPressGestureRecognizer
.
It works well right now, is that I've to lift my finger of the screen to see it appear.
Is there a way to make it appears after 0.5s (for example) even if the finger is still on the screen?
With the property of the UILongPressGestureRecognizer
?
EDIT:
class Settings: UIViewController , UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(Settings.deleteItem))
self.tableView.addGestureRecognizer(longPress)
}
func deleteItem(longPress:UIGestureRecognizer) {
if longPress.state == UIGestureRecognizerState.ended {
let pressedLocation = longPress.location(in: self.tableView)
if let pressedIndexPath = tableView.indexPathForRow(at: pressedLocation) { //Give the row where it's touched
RowSelected = (actionList?[pressedIndexPath[1]])!
print(RowSelected)
longtouched = pressedIndexPath[1]
let alert = UIAlertController(title: "What do you want to do?", message: "Select the action you want to do.", preferredStyle: UIAlertControllerStyle.alert)
let Cancel = UIAlertAction(title: "Cancel", style: .default) { actio in
print("Canceled")
}
let Delete = UIAlertAction(title: "Delete", style: .default) { actio in
//DOING MY STUFF
}
let Modify = UIAlertAction(title: "Modify", style: .default) { actio in
UserDefaults.standard.set(self.longtouched, forKey: "modify")
self.performSegue(withIdentifier: "ToModify", sender: self)
}
alert.addAction(Modify)
alert.addAction(Delete)
alert.addAction(Cancel)
self.present(alert, animated: true, completion: nil)
}
}
}