Roman Roman - 7 months ago 30
Swift Question

Two tab bar items with one view controller

I really need your help. I know that what my question contains not so good UI practices, but I need to do it...

In my app I have

with four items. The first item is "Channel" item, the third item is "Search" item. So, when users selecta "Search" item, I need show him "Channel" and searching something in
. I want that "Channel" and "Search" items have only one view controller -

I can present ChannelViewController, but then TabBar navigation isn't showing. I've written this code in

func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {

let channelViewController = self.storyboard!.instantiateViewControllerWithIdentifier("channelViewController") as! ChannelViewController
self.presentViewController(channelViewController, animated: false, completion: nil)


Can I do this without
? Can I just add or show/hide when I select "Search" item?

Is it possible do something like this:

override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
if tabBar.items?.indexOf(item) == 2 {
// and here some code to show tabBar.items with index 0

Any help is greatly appreciated!


Try this in one of your controllers:

self.tabBarController?.selectedIndex = 0