2

If have the app working when a custom UITableViewCell is tapped in the mainVC, i can edit the CoreData in the inputTableVC. Now i'am trying todo the same thing but then when the UITableViewRowAction "Edit" is tapped. The "Delete" function is already working.

Is there any way to implement the prepereForSegue or fetchRequest in the UITableViewRowAction?

Thanks in advance.

// Mark- My current working Segue code

override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
   if segue.identifier == "EditRaptor" {
   let customMainVCTableCell = sender as! CustomMainVCTableCell
   let indexPath = tableView.indexPathForCell(customMainVCTableCell)
   let addRaptorVC:AddRaptorVC = segue.destinationViewController as! AddRaptorVC
   let addRaptor:AddRaptorCoreData = fetchedResultController.objectAtIndexPath(indexPath!) as! AddRaptorCoreData
   addRaptorVC.addRaptor = addRaptor
  }
}
// Mark- The TableViewRowAction that needs to be fixed

public func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    let managedObject:NSManagedObject = fetchedResultController.objectAtIndexPath(indexPath) as! NSManagedObject


    var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete" , handler: {
        (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in

        self.managedObjectContext?.deleteObject(managedObject)
        self.managedObjectContext?.save(nil)

    })
    var editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit" , handler: {
        (action:UITableViewRowAction!, indexPath:NSIndexPath!) in



    })

    return [deleteAction,editAction]
}
DavyG
  • 21
  • 2
  • so you want to perform a segue on the edit action? – Firas Aug 09 '15 at 21:43
  • Yea... i like to perform the same action as when you tap a specific tableViewCell you go to the next viewController to edit the data. So for now i can do that with the prepareForSegue function. But thats not working when i call it within the action code. – DavyG Aug 13 '15 at 14:25
  • please check my answer, and accept it if it worked. – Firas Aug 14 '15 at 11:33

1 Answers1

0

I think what you need is to call performSegueWithIdentifier function inside the action code and then prepareForSegue will automatically get called before moving to the next viewController

Firas
  • 1,742
  • 15
  • 25
  • When i try your solution, i get the error that the mainVC Could not cast value of type to the CustomTableViewCell. I been trying to fix this for over a week but nothing seems to work. – DavyG Aug 16 '15 at 07:49