[英]How to swipe to edit text in a tableView?
在我的应用程序中,我有一个tableView,它具有默认文本,并且我希望通过滑动来编辑文本功能,以便用户可以根据需要更改文本。 我已经使用下面的代码添加了要删除的滑动,但是添加编辑文本功能并不是那么容易找到信息,所以我的问题是,如何添加按钮,以便用户可以通过滑动来编辑文本功能? 我需要知道加载文本的代码,因为我没有文本字段,所以它不像label.text = textfield.text
这样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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.