在我的应用程序中,我有一个tableView中的女巫,我具有默认文本,我想通过滑动来编辑文本功能,以便用户可以根据需要更改文本。
我已经使用下面的代码添加了要删除的滑动,但是添加编辑文本功能并不是那么容易找到信息,所以我的问题是,如何添加按钮,以便用户可以通过滑动来编辑文本功能?
我需要知道加载文本的代码,因为我没有文本字段,所以它不像label.text = textfield.text这样简单
原始加载文本的代码如下

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)

        cell.textLabel?.text = places[indexPath.row]["name"]

谢谢 !
 override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

        if editingStyle == UITableViewCellEditingStyle.Delete {

            places.removeAtIndex(indexPath.row)

            NSUserDefaults.standardUserDefaults().setObject(places, forKey: "places")

            tableView.reloadData()

        }
           }

最佳答案

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

  var editAction = UITableViewRowAction(style: .Normal, title: "Edit") { (action, indexPath) in
                tableView.editing = false

    // your action
            }

            editAction.backgroundColor = UIColor.grayColor()


    var deleteAction = UITableViewRowAction(style: .Default, title: "Delete") { (action, indexPath) in
                tableView.editing = false
    // your delete action
    }

    return [deleteAction, editAction]

07-28 03:13
查看更多