简体   繁体   中英

Swipe To Edit Details Swift and Parse

I am having trouble passing data to a new view controller to edit the fields when using a RowAction button.

I can get the RowAction button to go to the new view controller via the code below:

 override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?  {

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

        dispatch_async(dispatch_get_main_queue()) {
            self.performSegueWithIdentifier("EditDetails", sender: self)
        }   
    })
    return [editAction]
}

I can get the data to pass using a normal segue using the code below:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "EditDetails") {
        [segue destinationViewController].
        var editView = segue.destinationViewController as! EditDetailsTableViewController

    if let indexPath = self.tableView.indexPathForSelectedRow() {
            let row = Int(indexPath.row)
            editView.currentObject = objects[row] as? PFObject
        }

    }
}

However, I cannot seem to do both at the same time. I would like a user to be able to click the Edit button and the details for those fields populate and they can edit them.

Adding in proposed solution...however, still getting nil passed.

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

       let objectToEdit = self.objects[indexPath.row] as! PFObject
            self.performSegueWithIdentifier("EditDetails", sender: objectToEdit)

Are you just trying to pass values from some object in that row such as a textField? You can just save the current indexPath and grab them directly if there is some textField value you are needing or pass the row as sender in

self.performSegueWithIdentifier("EditDetails", sender: cell) // get the cell from the indexPath or just pass the indexPath 

Then you can use that in prepareForSegue

I just had the same issue. Check out the thread. At the bottom is my own answer.

Table row action to segue with indexPath row

Just send the indexPath, and then use it in the prepareForSegue to make it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM