UITableViewCell jumps to the detail view when I load a cell from nib?

I have a custom cell class and custom nib that contain the design for this cell. In my storyboard I don’t see a way to connect tableview as segue (as you have with prototype cells), I am there, since my cell is added via tableView:cellForRowAtIndexPath .

Is there a way to get this segue attachment so that I can continue to use the storyboard to connect the cell controller to the detail view?

Here is my code for tableView:cellForRowAtIndexPath :

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCellWithIdentifier("cell") as MyTableViewCell? if (cell == nil) { tableView.registerNib(UINib(nibName: "MyTableViewCell", bundle: NSBundle(identifier: "com.company.InterfaceComponents")), forCellReuseIdentifier: "cell") cell = tableView.dequeueReusableCellWithIdentifier("cell") as MyTableViewCell? } return cell! } 
+5
source share
2 answers

What I learned, I can do is add a manual section (by dragging and dropping from the controller) to the part controller (like Show segue with identifier: "showDetails"). Then I could add the following code to my table view:

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { self.performSegueWithIdentifier("showDetails", sender: tableView) } 

Which would give me the functionality that I wanted.

+4
source

This is what I do in Swift 3:

 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { self.performSegue(withIdentifier: "show", sender: tableView) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "show" { var indexPath = self.tableView.indexPathForSelectedRow let selectedRow = indexPath?.row let showVC = segue.destination as! NextViewController //do some pre-setting for next VC here with "showVC", "selectedRow" and other var you set in next VC } } 
+3
source

Source: https://habr.com/ru/post/1204714/


All Articles