AliSoftware/Dip-UI

Resolve view controllers in code

Closed this issue · 2 comments

Hi! I configured my view controller following a guide and I try to resolve an instance of view controller like this:

let viewController = try! container.resolve(tag: "myVC") as TestViewController

I get the instance of TestViewController, but it doesn’t have outlets and all the stuff that I set in the storyboard. Does DipUI work only when you create all view controllers with segues? Is there any way to resolve instances in code?

For that you need to register controller with custom initialiser or factory that creates controller from storyboard

container.register(tag: "myVC") { TestViewController(/*pass in all properties*/) }
container.register(tag: "myVC") { TestViewControllerStoryboard.instantiateViewController(identifier: ...) }

Oh, it works! Thank you very much=)