0

How to display the uitableview's swipe option on didselectRow:

want to display swipe option like below.enter image description here

exmaple show in fig, this should implement in didselect row. How can achive this help me. Thanks advance.

SPatel
  • 4,768
  • 4
  • 32
  • 51
saravanar
  • 639
  • 2
  • 11
  • 25

1 Answers1

0

First , you should sure that:

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // the cells you would like the actions to appear needs to be editable
    return true
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    // you need to implement this method too or you can't swipe to display the actions
}

and second you will implementate in this delegate method:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    let more = UITableViewRowAction(style: .Normal, title: "More") { action, index in
        println("more button tapped")
    }
    more.backgroundColor = UIColor.lightGrayColor()

    let favorite = UITableViewRowAction(style: .Normal, title: "Favorite") { action, index in
        println("favorite button tapped")
    }
    favorite.backgroundColor = UIColor.orangeColor()

    let share = UITableViewRowAction(style: .Normal, title: "Share") { action, index in
        println("share button tapped")
    }
    share.backgroundColor = UIColor.blueColor()

    return [share, favorite, more]
}

the finall view like that: enter image description here hope this is helpful for you.

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30