ios - TableView action doesn't show -


i created uitableviewrowaction these code:

func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {      var deleteaction = uitableviewrowaction(style: uitableviewrowactionstyle.default, title: "delete", handler: {(action:uitableviewrowaction!, indexpath: nsindexpath!) -> void in          })      if editingstyle == uitableviewcelleditingstyle.delete {          let delegate = uiapplication.sharedapplication().delegate as! appdelegate         let managedcontext = delegate.managedobjectcontext!          var error: nserror?          let fetchrequest = nsfetchrequest(entityname: "task")          let fetchedresults = managedcontext.executefetchrequest(fetchrequest, error: &error) as! [nsmanagedobject]          managedcontext.deleteobject(fetchedresults[indexpath.row])         table.deleterowsatindexpaths([indexpath], withrowanimation: uitableviewrowanimation.fade)      } 

when run it, rows can swiped left, no button shown.

i added this:

func tableview(tableview: uitableview, editactionsforrowatindexpath indexpath: nsindexpath) -> [anyobject]? {      let deleteaction = uitableviewrowaction(style: uitableviewrowactionstyle.default, title: "delete", handler: {(action:uitableviewrowaction!, indexpath: nsindexpath!) -> void in      })      deleteaction.backgroundcolor = uicolor.redcolor()      return [deleteaction] } 

and deleted code in commiteditingstyle, , still doesn't show.

if want uitableviewrowaction,you delegate method not right

try this

override func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {  } override func tableview(tableview: uitableview, editactionsforrowatindexpath indexpath: nsindexpath) -> [anyobject]? {     let action = uitableviewrowaction(style: uitableviewrowactionstyle.default, title: "first") { (action:uitableviewrowaction!, indexpath:nsindexpath!) -> void in         //do action here     }     action.backgroundcolor = uicolor .greencolor()       return [action] } 

screenshot

enter image description here


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -