how to make UITableview
editable, I am using EDITActionsForRowAtIndexPath
delegate for editing cell
My code :
let infoAction = UITableViewRowAction(style: UITableViewRowActionStyle.Destructive, title: "More", handler: { (action , indexPath) -> Void in
let MoreInfo = UIAlertController(title: "More", message: nil, preferredStyle: .ActionSheet)
MoreInfo.addAction((UIAlertAction(title: "Flag This conversation", style: .Default, handler: { (UIAlertAction) -> Void in
print("flaged")
self.tableView.setEditing(true, animated: true)
self.tableView.editing = true
})))
MoreInfo.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
print("Cancel")
self.presentViewController(MoreInfo, animated: true, completion: nil)
})
don't use uialert, try this snippet:
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let deleteClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
println("Delete button pressed")
}
let moreClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
println("More button pressed")
}
let deleteAction = UITableViewRowAction(style: .Default, title: "Delete", handler: deleteClosure)
let moreAction = UITableViewRowAction(style: .Normal, title: "More", handler: moreClosure)
return [deleteAction, moreAction]
}
this should show 2 buttons: one red with delete text and one gray with more text; you can customize as you prefer :)
source: http://pablin.org/2014/09/25/uitableviewrowaction-introduction/
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.