Ulli H Ulli H - 3 months ago 5x
iOS Question

how to get the last selected row in a UITableView before a segue is executed

i have inserted a new row in a UITableView and now i tap another cell (also highlighted through a breakpoint in the debugger, after that, only the tapped row is selected):

enter image description here

the new row (UITextField) has the text "new" and the selected cell has the title "Hobby"

On the tap of the now selected row/cell "Hobby" i must fire a segue to another TableViewController (ColumnViewController)

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if self.currentEdit != nil {
if segue.identifier == "SetupColumn" {
let cell = sender as! EditCell
let destControlller = segue.destinationViewController as! ColumnViewController
destControlller.kategorieID = cell.nameField.tag

but i must know, that the row/cell "Hobby" is tapped cause i have to popup an alert before calling the segue. I only must know, that the row is different to the added one, not which row is tapped.

self.currentEdit contains the actually selected TextField, but there i just have the added row. :-(


I got the answer of beyowulf, that can you see below. I thought, the problem is solved, but when playing with it some time, i suddenly (!?) get the error

app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'SetupColumn''

The answer of beyowulf was:

Don't connect your segue to the your table view cells. Connect it to your view controller then call it explicitly when you want to segue

My question is now: how may i connect my segue to my view controller instead connecting it to the table view cell?


Does tableView.indexPathForSelectedRow give you what you need?

To add a segue from your view controller, right-click on it and choose "Triggered Segues", drag from the 'manual' row to the segue's destination.