I have a tab bar controller which has two items connected to two view controllers(say A & B) now I want to add a 3rd view controller (say C). But I don't want to add a third icon in tab view. When the user select the second icon it should render B or C depending on whether user has signed in or not.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Just create another view controller for the tab bar item for which you want to display different views depending on the context. Let's call it RouterViewController
. Then pass the information you need to decide which view controller to show to that RouterViewController
and implement the necessary logic there.
From the RouterViewController
you can now present whatever view controller you want (without animation). There are plenty of ways to do this, for example:
- Make your
RouterViewController
a subclass ofUINavigationController
and dynamically set itsrootViewController
property. - Make your
RouterViewController
a container view controller and embed the desired view controller accordingly. - Present a view controller modally (without animation) from your
RouterViewController
. (I personally would discourage this option because presenting modal view controllers is intended for another purpose.)
etc.