I'm stuck trying to pass a parameter between two UITableViews within XCode with Swift.
I've seen a handful of questions asked here on SO but even though I followed instructions, I'm still stucked.
I've set up my Storyboard. I had a problem here because most of the guide I found use the "Show" Segue but for some reason I can only use the "Push" Segue. There's no way I can drag and create a "Show" Segue (maybe because I'm using the Mac via Remote Desktop on Windows and Mac isn't understanding Ctrl/Command Key?)
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedIndex = indexPath.row
}
override func prepareForSegue(segue: (UIStoryboardSegue!), sender: AnyObject!) {
if (segue.identifier == "secondSegue") {
let controller = segue.destinationViewController as! SecondViewController
controller.valuePassed = selectedIndex
}
}
Even though it works, for some reason, the index passed is never the current one. Instead, the index received on the second screen is the previous selected one.
I also tried using "performSegueWithIdentifier" but with that my second screen opens twice when I click an item. I assume it's because there's a "Push" link between them along with "performSegueWithIdentifier".
I don't know how to create a Segue identifier without linking both screens on the storyboard.
So, I'm not sure if my code is wrong, if I should somehow create a "Show" Segue (I'm really new with iOS programming and I don't know the actual difference between Push and Show on the context of UITableView), If I should somehow create the Segue identifier without linking the screens on the storyboard, and so on... I'm really stuck and out of ideas.
Appreciate any help. Thanks.