I am new to iOS programming and I was looking for how to do this, but I can't seem to find what I'm looking for. I thought it would be a fairly simple task, and I am sure that if someone can enlighten me.
When scrolling left on the table view, I have some user actions that can be performed. One such action is to simply “Edit” the selected item. All I want to do is display another view controller, but pass some data to this view controller, as is usually done in prepareForSegue (...).
Here is what I have. See Section "// Option 2" ...
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(
style: UITableViewRowActionStyle.Normal, title: "Delete", handler: deleteHandler);
deleteAction.backgroundColor = UIColor.redColor()
let editAction = UITableViewRowAction(
style: UITableViewRowActionStyle.Normal, title: "Edit", handler: editHandler);
editAction.backgroundColor = UIColor.grayColor()
return [deleteAction, editAction]
}
func editHandler(action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void {
let myViewController = ItemViewController()
let selectedItem = self.items[indexPath.row]
myViewController.item = selectedItem
self.presentViewController(myViewController, animated: true, completion: nil)
}
func deleteHandler(action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void {
self.games.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
editHandler? segue, , , .
!