senty
senty

Reputation: 12857

Segue from Static Cells to Dynamic TableViewController

I have a TableViewController that has static cells inside groups. I want to perform segue from some of the static cells, but also somehow know which cell triggered the segue in the segued TableViewController.

I ctrl + dragged from each cell to the destination TVC, added segue identifiers and created a class for TVC.

I this approach, but the segue doesn't work. It doesn't print XOX either

class MainTableViewController {

  viewDidLoad() {
     tableView.delegate = self
     tableView.dataSource = self
  }

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
      print("XOX")
      if segue.identifier == "MainToA" {        
        if let destination = segue.destinationViewController as? DetailTableViewController {
                destination.page = "A"
        }
      }

     if segue.identifier == "MainToB" {        
       if let destination = segue.destinationViewController as? DetailTableViewController {
               destination.page = "B"
       }
     }
  }

class DetailTableViewController {

    var page = String()

    viewDidLoad() {
         print(page)
    }
}

Am I missing out something or completely out of track? Why doesn't the segue work?

Upvotes: 0

Views: 710

Answers (3)

George_78
George_78

Reputation: 11

Try enabling the Selection property in your Table View Static Content

Attributes inspector, as shown in the picture here.

Upvotes: 1

Shubhank
Shubhank

Reputation: 21805

I tried and the segues work correctly with connection to individual UITableViewCell

You can see in the image the triggered segue part

Please make sure you have connected the segue from the cell instead of any subview inside it.

Edit

From the chat it appears you have a UITapGesture which takes up the touch of the view. To avoid this i would suggest to removeTapGesture and use tableView didSelectRow methods to detect touches on view

Upvotes: 1

Curmudgeonlybumbly
Curmudgeonlybumbly

Reputation: 639

Did you subclass UITableViewController? Did you assign that subclass in Interface Builder? Did you make sure NOT to implement override func numberOfSectionsInTableView(tableView: UITableView) -> Int so that your static cells actually appear?

When you ctrl+dragged did you link up Triggered Segues by Selection, not Accessory action?

Upvotes: 1

Related Questions