Gettings reference to existing navigation controller in tab bar after receiving remote notification - ios

My app consists of following:
Tab bar controller with 5 tabs (this is my init controller)
each tab bar item has navigation controller and another view controllers further in
Now, I'm implementing skype-like chat (table view with contacts and chat as a detail view of this table view), which is currently residing in my second tab bar item, about 2 views deep in hierarchy.
When I receive remote notification, I want to preserve user navigation stack in all tabs, so instead of recreating tab bar in appdelegate, I just want to get reference of my navigation controller, that is in my second tab (so that I can modify it's navigation stack later on).
My problem here is, that I just can't get the reference. I got my tab bar like:
UITabBarController *myTabBar = (UITabBarController *)self.window.rootViewController;
but then I don't have any clue what to do. I will be happy for any suggestion.

The answer is (UINavigationController*)[myTabBar viewControllers][1] :)

Related

Using UITabBarController with UINavigationController - Swift 3

I am making an app which requires a use of a UITabBarController along with UINavigationController. I have made the following flow in storyboard.
See image
Now the first question is that is this accepted by Apple, as there are too many discussions for the same.
The other matter of concern is that is it possible to eliminate any UINavigationController and still get the same flow of the app? The main thing required is to have the SAME tab bar and navigation bar on all sub tabs of the tabs. One point to be noted is that if I remove the second UINavigationController then my app navigates directly from sub tab to home view controller on clicking back button.
I have been stuck on this since hours now. I am new to iOS app development and have never uploaded any app to the app store. Any help would greatly valued.
EDIT :
I put the second navigation controller as shown in the answers - see this flow, But because I have a navigation controller before the HomeViewController, so I am getting a navigation bar at the top and then some empty space below that(exactly equal to the top navigation bar) and then the page contents on runtime. Any solution to this?
Yes, it is acceptable by Apple.
But View hierarchy is not managed correctly. In your case Tab bar will be the root view controller for 2nd navigation controller.
Also, Tab and sub tab you are pushing will be part of 2nd navigation controller.
That's the reason you are getting back on Home view controller.
It's good practice to keep navigation controller to each Tab to manage it's sub-tab hierarchy.
You could present tab bar controller or setviewcontroller from Home View controller.
First embed tab bar controller as in this image and the embed navigation bar controller as in this image finally this will look like

Having problems with combined tab bar and navigation bar controllers

I am having a problem with the back button not going to the previous view controller despite me using segues (via push). I think there is a problem since I saw this line on Apple's documentation saying
"An app that uses a tab bar controller can also use navigation controllers in one or more tabs. When combining these two types of view controller in the same user interface, the tab bar controller always acts as the wrapper for the navigation controllers."
But I want to be able to use a login screen which then moves onto a couple of screens before getting to a tab bar controller therefore not having the navigation bar wrapped in the tab bar controller. I know many popular apps use this, for example Instagram where you login then it shows the tab bar controller.
My current app layout is this;
Root navigation controller -> login -> meals (gif) -> tab controller (navigation controller for each tab (as per link) -> (My Rota/ My Meals/ Shopping List/ Item)
How to implement tab bar controller with navigation controller in right way
It looks like it is behaving as expected, the back button is for your root navigation controller and when you use the 'back' button it pops your tab bar controller. I actually expected you to see two navigation bars, your root one and the one in the My Meals tab, unless you hide one.
You could hide the root navigation bar when you push the tab bar, but you'll probably need a button in each tab's navigation bar which pops the tab bar from the root navigational controller.
Beyowulf's suggestion of presenting it as a modal is another option.

How to prevent tabbar from hiding with SWRevealViewController?

I'm trying to find out why any ViewController, that I push onto navigation stack does not show tabbar. Now I have construction like this:
loginVC -> navigationController -> SWRevealVC --> (leftPanelVC and second segue is to tabbarController, which has 4 its own view controllers). When I push view controller from any of this 4 controllers I'm loosing my tabbar and I cannot bring it back. Tried hidesBottomWhenPushed but it didn't work out as expected. Anybody?
EDIT:
What I just tried, was to set connections like this: login -> tabbarcontroller -> as first subcontroller I set up SWRevealViewController and hooked to it front navigationController and rear tableController. Unfortunately it messes stuff a bit, because tabbar now stays always, even on top of rear controller... the look I'm trying to get is interaction like in facebook app, where tabbar is always visible, but as a part of front controller, not overlaying rear.
When I push view controller from any of this 4 controllers I'm loosing my tabbar and I cannot bring it back.
I am not sure what you are doing here, but as far as I understand, you have:
pushed a tab bar controller on to a navigation controller;
from that tab bar controller, pushed a new view controller on to the navigation controller.
It that is correct, than it is normal that your tab bar controller tab bar "disappears" since you are pushing a new view controller (point 2) on to the navigation controller and this will replace the tab bar controller as the top most controller in your navigation controller.
Possibly, what you are looking for can be obtained by embedding a navigation controller inside of a tab bar controller, but I do not have enough info about your UI to be sure this makes sense.

How do you change views from a Tab Bar Controller

I am developing an app that consists of a Tab Bar Controller that points to 3 view controllers (all with tabs). In one of these tab views I've made a button and I want it to open a new view (without a tab at the bottom). This new view would need a navigation bar with a back button to return to the previous view, so I was thinking I need to create a navigation controller?
Essentially this is what I'm trying to do (I apologize for the poorly drawn diagram).
How can I get this new view (entirely independent of the tab bar controller) to display programatically? Would this require a navigation controller?
You are describing a presented view controller. Call presentViewController:animated:completion:.
I very frequently do this with a navigation bar and a Back or Done button, just as you describe. But it's not a navigation controller or navigation interface; it's just a convenient way of showing the user how to get back.
For example, this is a presented view in one of my apps. The top is a navigation bar, and the cancel button gets us back (call dismissViewController...). The rest is a scrolling view (a UICollectionView) of buttons.
[myTabBar setSelectedIndex:1]
You may have to access the tabBar like self.tabBarController so… [self.tabBarController setSelectedIndex:1];
1 is index 1 in the tabbar's stack (this is like tapping a tabBar button manually)

Navigation bar from tab bar controller hides child's nav bar

I am confused with behavior, I have Tab Bar Controller ( I enter on this controller from simple view controller which is embedded in navigation controller). I am confused why is that navigation bar from tab is covered up child navigation bar.
When I start app and I enter at Browse Controller I cannot see Browse title, neither nav bar items which I added programmatically. Can somebody give me clue what is wrong ( I am new to this, I connect with push segue from tab to browse).
Your problem appears to be the same as the one I addressed here:
Push segue from a view controller controlled by UITabBarController
What's happening is that your first NavigationController is creating a Navigation stack. Then you push-segue a TabViewController. That is added to the Nav stack, along with each of it's contained view controllers. However, when you PUSH SEGUE from one of those view controllers to some other view controller, the original navigation controller's stack is the one you are pushing on to. This is not contained inside the tab view controller, so the pushed view controller has no relationship with that tab view controller, just the original navigation controller stack. Therefore the tabs are not present.
The answer is to embed each of the tab controller's view controllers in a new navigation controller, and push on from those. The original navigation controller is just messing things up here...

Resources