滑动以编辑细节Swift和Parse

滑动以编辑细节Swift和Parse

本文介绍了滑动以编辑细节Swift和Parse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用RowAction按钮时,我无法将数据传递到新的视图控制器来编辑字段。

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

我可以通过以下代码获取RowAction按钮转到新视图控制器:

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]
}

我可以使用以下代码使用普通的segue获取数据:

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.

添加建议的解决方案......但是,仍然没有通过nil。

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)


推荐答案

我遇到了同样的问题。请查看主题。底部是我自己的答案。

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

只需发送indexPath,然后在prepareForSegue中使用它让它发挥作用。

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

这篇关于滑动以编辑细节Swift和Parse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 03:48