How to change class dynamically for view controller using interface builder

会有一股神秘感。 提交于 2020-01-06 06:06:58

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/49270459/how-to-change-class-dynamically-for-view-controller-using-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!