Meu código não funciona, não consigo identificar o por que. Alguém tem alguma ideia?
func showDetails(recognizer: UILongPressGestureRecognizer){
if recognizer.state == UIGestureRecognizerState.Began {
let cell = recognizer.view as! UITableViewCell
let indexPath = tableView.indexPathForCell(cell)
if indexPath == nil {
return
}
let row = indexPath!.row
let meal = meals[ row ]
RemoveViewController(controller: self).show(meal, handler: { action in
self.meals.removeAtIndex(row)
self.tableView.reloadData()
})
}
}
e
class RemoveViewController{
let controller: UIViewController
init(controller: UIViewController){
self.controller = controller
}
func show(meal:Meal, handler:((UIAlertAction!) -> Void )){
let details = UIAlertController(title: meal.name,
message: meal.details(),
preferredStyle: UIAlertControllerStyle.Alert)
let remove = UIAlertAction(title: "Remove",
style: UIAlertActionStyle.Destructive,
handler: handler)
details.addAction(remove)
let cancel = UIAlertAction(title: "Cancel",
style: UIAlertActionStyle.Default,
handler: nil)
details.addAction(cancel)
}
}