0

please help. I need send data from view to new view. I have that StoryBoard. StoryBoard

In first view i have code

override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "LEDChangesSegue" {
        let changeLED = segue.destinationViewController as? AddLED
            changeLED?.senderCell = sender as? LEDListCell
            changeLED?.ledController = sender!.ledController
            changeLED?.update = true
    }
}

this method worked when I use push segue, but now I use modal segue and in segue.destinationViewController is NavigationController, not my TableViewController

MacSergey
  • 15
  • 7

2 Answers2

1

Use the new destination as VC to call your next tableViewController

let destination = segue.destinationViewController
if let navcon = destination as? UINavigationController {
    destination = navcon.visibleViewController!
}
if let hvc = destination as? TableViewController{
   // do whatever
}
Abdoelrhman
  • 906
  • 8
  • 17
1

Each navigation controller has array of presented controllers. As well if your Controller is on top(is shown right now) you can use this code to get it navigationController.topViewController Otherwise you need to go through all controllers and get yours using this code

let navController: UINavigationViewController = segue. destinationViewController
for let controller in navController.viewControllers {
    if let neededController = controller as? YourControllerType {
   // your action
}
}

As well you can create your custom segue with IBInspectable property of UIViewController that will store your controller inside. After that you can cast this your segue to your custom segue and get your controller from that property.

Volodymyr
  • 1,165
  • 5
  • 16