Tab bar controller selectedIndex or SelectedViewController accessor - iphone

I have created a tabbar based application which contains, let say, 3 tabs. In my first tab, I have 3 UIButtons. on clicking button 1, a new viewcontroller 1 is loaded and the tab 1 is highlighted as selected. On clicking button 2, a different view is loaded (Viewcontroller 2) and tab 2 should be highlighted as selected tab (Remember, this viewcontroller 2 is not the root view controller of tab 2) and on clicking button 3, again a new view is shown (viewcontroller 3) and tab 3 should be highlighted as selected (Remember, this viewcontroller 3 is not the root view controller of tab 3).
So, what I want to do is, I want a particular tab to be shown as selected (or highlighted), but dont want to load its root view controller.
I have tried using tabbarcontroller.selectedindex = 1 on clicking of button 1, but it went in vain. Because what happened was tab 1 got selected and the view being shown to me was not viewcontroller 2. Instead it was the root view controller of tab 2. Somebody pls get me out of this mess....

If that is indeed your requirement, the best way is to create a 'fake' tab bar using custom uiimageview. You will need three imageview and change the images accordingly as you tap the buttons.

Related

How to embed in a viewcontroller without tab bar when the parent is a tab bar viewcontroller?

My current hierarchy is:
Tab bar controller
Navigation controller
A UIViewController
Another UIViewController
It shows tab bars at the second UIViewController (so number 4 in the list). I want to remove that tab bar, but I want to keep the navigation at the top. This is because the first UIViewController (number 3 in the list) holds a tableview, and when a user clicks on a cell it goes to the second UIViewController and I want to keep a back button.
An example is when you open WhatsApp, you have a list of conversations (left side of image). When you click on a conversation, the tab bar buttons at the bottom are gone (right side of image). I can hide them in the second UIViewController, but it causes some glitches. I am sure there is a better solution.
In presented/pushed viewController's viewDidLoad, or in the storyboard, set the view controller's hidesBottomBarWhenPushed to true.

Swift 3: Show Tab Bar on an other ViewController

I'm using a tab bar which is connected to 3 viewControllers. What I want to do is when I click the some rows on my main viewController, I want to keep my tab bar for this page.
This is my main viewController on the tab bar:
When I click on a tableView's row on the left side, I want to keep the tab bar on the other page in its place. I guess I have to do something in the prepare for segue function. What do you guys think?

Reload UITabbarController when change selected index

I have a UITabBarController With the 2 Tabs. I want When I click on the Tab 2 (viewController B) then click on the Next button with navigationcontroller (viewController C). Then, I click Back button (custom button) to come back to Tab 1 (ViewController A) and I want when again I come back to Tab 2 the view controller should be display viewController B.
Thanks !
On the custom button (Back button) action you should call popViewController and then jump to Tab 1. or when pressing on the Tab 2 you can check if you are in the root view controller of the navigationcontroller and if not put ViewController B as the root.

Remove tabBar from view

I have a tab bar app w/ the following drill down flow:
view 1 > view 2 > view 3 > view 4
I'd like to remove the tab bar from view 2 and keep the tab bar on views 1, 3 and 4.
I tried setting the code below when loading view 2.
vc.hidesBottomBarWhenPushed = YES;
The code successfully removes the tab bar on view 2, but I can't get the tab bar to come back on views 3 and 4. I assumed I'd be able to set YES to NO (vc.hidesBottomBarWhenPushed = NO;) when views 3 and 4 are selected to bring back the tab bar, but that doesn't work.
How can I remove the tab bar on view 2 only (keep the tab bar on views 1, 3 and 4)?
Overwrite the init function (loadView probably won't work) for views 3 and 4 and set
self.hidesBottomBarWhenPushed = NO;
That should work.

Navigation back to main view

I have a root view controller as the navigation controller. In the root view controller nib file I have 3 buttons (button 1, button 2, button3). Each of which has a table view contoller Eg: Flow of the buttons (I have followed the navigation logic such that at any time I can get back to the root view controller by selecting the back button).
On Button 1 click => table view shown ==> detail view shown on item click/selection
On Button 2 click => table view shown ==> detail view shown on item click/selection
This logic holds good for all the buttons. In the detail view I have a button.
What I want is on the click of this button, the button 3 logic should be called such that, when i click or press the back button from the table view of 3rd button, I should get back to the main root view controller with all the buttons visible.
Please let me know how should i go ahead with the same.
I believe you'll want to use the - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated found in UINavigationController. As the name suggests, this will allow you to pop back to the root view controller at any time.