0

So I've been trying to get any row to act like a segue to the next class, kind of like how if you swipe left you can delete the row, after adding the func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)

but instead in stead of deleting it I would like it to show the another class. If anyone could help it would be great thanks

M.Larry
  • 3
  • 1

2 Answers2

0

If I'm understanding the question correctly, you would like so that the user would swipe left on a cell, and it would trigger a segue?

If this is the case, you could try adding a UISwipeGestureRecognizer to the cell using the addGestureRecognizer method, within the cellForRow method of the UITableViewDataSource class.

Hope this helps!

Jason
  • 635
  • 1
  • 9
  • 21
0

You can add swiprgesturerecognizer something like,

 class MyViewController: UITableViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    var recognizer = UISwipeGestureRecognizer(target: self, action: "didSwipe")
    self.tableView.addGestureRecognizer(recognizer)
}

func didSwipe(recognizer: UIGestureRecognizer) {
    if recognizer.state == UIGestureRecognizerState.Ended {
        let swipeLocation = recognizer.locationInView(self.tableView)
        if let swipedIndexPath = tableView.indexPathForRowAtPoint(swipeLocation) {
            if let swipedCell = self.tableView.cellForRowAtIndexPath(swipedIndexPath) {
                // Swipe happened. Do stuff!
            }
        }
    }
}

}

This was an example, manage it as your need. you can add swipegesture's direction property for handle particular direction's swipe like UISwipeGestureRecognizerDirection.Left or Right.

You can refer this answer as a reference.

Hope this will help :)

Community
  • 1
  • 1
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • Thanks that really helped. Just one more thing. Rookie question but how do you perform the segue in the code. So in your answer when you say "// Swipe happened. Do stuff!" how do I then get it to show the other class? – M.Larry Jun 01 '16 at 02:28
  • You can performsegue something like `performSegueWithIdentifier("mySegueID", sender: nil)` here `mySegueID` is segue identifier set from the interface builder from attribute inspector with segue selected – Ketan Parmar Jun 01 '16 at 04:30