Developer
Developer

Reputation: 764

Accessing a UIViewController using storyboardID without instantiating it

Is there any way to access a UIViewController without using the function instantiateViewController(withIdentifier: String). I have to call the function tableView.ReloadData() from within another UIViewController which I have transitioned to using a show segue and I therefore do not want to instantiate the initial UIViewController again.

Thanks.

Upvotes: 0

Views: 41

Answers (1)

xmhafiz
xmhafiz

Reputation: 3538

You can access through UINavigationController stack. Let say if it is one controller before, you can access it using the total viewcontrollers (in stack) minus 2

let previousController = self.navigationController?.viewControllers[(self.navigationController?.viewControllers.count)! - 2] as! YourViewController

more simplified

let controllerIndex = (self.navigationController?.viewControllers.count)! - 2
let previousController = self.navigationController?.viewControllers[controllerIndex] as! YourViewController

Upvotes: 1

Related Questions