How to change class dynamically for view controller using interface builder
Asked Answered
E

2

0

there are different conditions for same design file. i can't use if-else in same class file to differentiate them. because manage all conditions are difficult. is there any way to change class at dynamic time.

Eelpout answered 14/3, 2018 at 5:43 Comment(2)
Have a look here on how to do it with NIB files. https://mcmap.net/q/174128/-how-to-use-single-storyboard-uiviewcontroller-for-multiple-subclassSasaki
Look here on doing it with Storyboard. https://mcmap.net/q/174128/-how-to-use-single-storyboard-uiviewcontroller-for-multiple-subclassSasaki
E
0

Yes, we can set class using Xib. But from my research i didn't find any way to change storyboard class dynamically. I found other way to reuse the view like using container view. following link shows how can we reuse storyboard view. Diego Lavalle describe it on medium.

and you can read about container view at here.

Eelpout answered 5/9, 2018 at 11:20 Comment(0)
T
0

I think you can use a master view controller and can load different view controllers as child based on some condition.

For example in Master View controller you can use UIsegmentedControl and based on the option the user chooses, you can show different view controllers.

Refer the following for implementing the same.

https://medium.com/@Dougly/creating-a-custom-view-controller-navigation-interface-programmatically-swift-3-1-8c9e582cdb30

Transubstantiate answered 5/9, 2018 at 11:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.