loading view controller embedded inside navigation - ios

Im trying to create a loading view controller before it loads my tableView. This works fine.
However when the tableView is displayed I get a back button. When clicked it takes me back to the loading view. Im guessing this is because its embedded inside of the navigation controller. Please advise.

if you want to hide the back button just add
self.navigationController.navigationBarHidden=YES;
in the third View controller's viewDidLoad
else add
self.navigationItem.hidesBackButton=YES;

You have different options to choose from, depending on your needs:
The loading view can push the navigation controller.
You could avoid using a full view controller to do your loading, and instead just set a view above the rest of your "offers view controller".
Or, refers to Raon answers if you just want the button to disappear

The navigation controller will keep all the controllers that you pushed in a navigation stack.
So if you push ladingviewcontroller using navigation controller and then pushing tableview controller the navigation stack will contain both the controllers and thats why on pressing back button, you are navigated to loadingViewController.
What I suggest is to remove loadingviewcontroller and show loading view in your tableviewcontroller before loading the tableview. Like, in viewWillAppear of tableviewcontroller, just add a UIView with loading indicator and add it as a subview of tableviewcontroller and remove it after you are ready to show your tableview.

Well, if you just want to hide the back nav bar button, you can do this
[self.navigationController.navigationItem setHidesBackButton:YES animated:YES];
But the better way to show the loading controller's view would be this,
[self.view addSubview:loadingController.view];
[loadingController willMoveToParentViewController:self];
[self addChildViewController:loadingController];
[loadingController didMoveToParentViewController:self];
just hide it or remove it from superView when loading view is not required. You can even animate it while hiding so that it gives a nicer effect.

Here we have a architecture issue, the best way is the following:
Make the 2 and 3 view a single one. I mean you must add the ActivityIndicator at the center of the view that contains the table view.
Make the table view hidden and startAnimating the UIActivityIndicatorView.
Do all your loading stuff.
When you finish loading, stopAnimating your UIActivityIndicatorView and make the table view visible again.
And that's it ;)

Do not push the offers load view controller via navigationController, just subview its view on the offersviewcontroller (the third one) like this in the viewDidLoad method:
OffersLoadViewController *offerLoadView = [[OffersLoadViewController alloc] initWithNibName:#"OffersLoadViewControllerv" bundle:nil];
[self.view addSubview: offerLoadView.view];
After dealing with loading just remove it:
[offerLoadView.view removeFromSuperview];

Related

Dismiss Modally presented view makes tab bar controller (kind of) reset

I have an app which has tab bar controller as main controller. Each tab has a series of views with navigation controller and I normal push and pop those view in stack.
Weird problem is
Case 1 : If I create a UINavigationController and make a new viewController as its root, and present this NavigationController. Within this new navigation stack, I can easily present a view modally and dismiss it without a problem.
Case 2: Now without make a new UINavigationController, I present a view, and when I dismiss a view, the view beneath is behave weirdly. For example, it's the presenting view was UICollectionView, it just scroll back to 1st cell, like it's doing "reload" action and "scrollTo" the first cell. If the presentingView is a pushed view from rootView, it will just popToRoot view, which is definitely not intended.
I didn't have this problem until I implement UITabbarController, so I guess, I should know more that's going on under the hood when presenting a view and dismiss a view in UITabbarController.
I GUESS, when dismiss a view in UITabbarController view, it sort of "RESET" everything to the very first view of it's current tab. I really am not sure it's trure though.
I know it's kind of conceptual, but I can't help to think there must be something critical I am missing here.
I made silly mistake that I sublclass UITabbarController and define navigation controlllers in viewDidAppear instead viewdidLoad, so when I make the window's rootview to tabbar controller, the navigation controllers are not set properly. That's why all punky things happened. It would be nicer if just crash instead of this weird behaviors.
You can try this to go back to your first viewcontroller.
- (IBAction)buttonPressedFromVC2:(UIButton *)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
} // This is going back to VC1.
This method is will be in second viewcontroller.m file. It is button click method.

Unable to configure UINavigationBar for view embedded in Tab Bar Controller

I a writing an app (iOS8) that ultimately needs to load a UITabBarController via a segue from a UITableView. For the most part this setup can be done via Storyboards and works as expected, however I would also like to add a UIButtonBarItem to the destination view which is where the problems start.
A setup that works (without a UITabBarController) can be configured as follows
The button uses a "Show" segue to display the final view controller
The second UIBarButtonItems are added by copying over the Navigation Item from the first view controller (How to add buttons to navigation controller visible after segueing?)
If I run this in the Simulator, everything works as expected and I see both the back button and the desired "Add" UIBarButtonItem:
If I then embed the final view controller in a UITabBarController, the UIBarButtonItem I added disappears and so far any changes I have made to the storyboard setup (adding a UINavigationController in between the UITabBarContoller and the last view for example) or attempts to add the UIBarButtonItem programatically don't make a difference:
Is there anyway to get the final setup working with both a UITabBarController and UIBarButtonItems?
I have the same setup in one of my apps and it works fine. Not sure why you are having issues, but I did add a few lines of code in my custom Tab Controller that may help you. I think the issue is that the nav bar from the original navigation controller is still being shown, so subclass UITabBarController and put these lines in viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationItem setHidesBackButton:YES];
[self.navigationController setNavigationBarHidden:YES];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
In my app, the views before the tab bar controller were login/register views, so there was no reason to navigate back to them after entering the tab controller "stack," but I'm sure it won't be difficult to add a back button that accomplishes this. I believe you only need the [self.navigationController setNavigationBarHidden:YES]; line, which only hides the nav bar instead of hiding the back button or disallowing the pop gesture.
I know this is late but I just want to add swift 3 code.
The reason being that the NavigationBarA of the tabBarController is hiding your NavigationBarB that sits in between your tabBarController and the final ViewController. So you just have to set to hide the NavigationBarA
in viewWillAppear of your final ViewController you can add the following (without a need to subclass tabBarController)
self.tabBarController?.navigationController?.setNavigationBarHidden(true, animated: false)

Subview button disappears on back button

I was trying to implement an overlaying button over UITableView in my UIView.
That's what I did:
Created button in Storyboard
Ordered elements:
In my viewWillAppear added:
[self.navigationController.view addSubview:self.myBtn];
It seems enough to display it correctly, but when I perform segue forth the next view I still see this button. That's why I added this in segue:
if ([[segue identifier] isEqualToString:#"addEvent"]) {
[self.myBtn removeFromSuperview];
}
Now it disappears on the next screen, but if I tap back on it, this button won't appear on my previous view. What's wrong?
If you know other ways to implement floating foursquare-like button, I'm opened to it. The simple way described here isn't working: UITableView overlays the button.
Button is placed below the table view. All that you need is swap table view and button in storyboard.
[self.navigationController.view addSubview:self.myBtn];
A navigation controller's view is probably regenerated each time the navigation stack changes. That would cause the button that you added to the nav controller's view to disappear.
In general, you should avoid messing with another view controller's view hierarchy. If you want to add a button over your table, that's fine, but do it in the context of your own view controller's view hierarchy.

going back inside navigation controller through embedded view controller

In my iOS project I have a main menu that is shown embedded in a container in my initial UIViewController.
After the user choses any row in that menu, the navigation controller pushes the submenu viewController that manages further actions, which uses the full window.
If the user wants to go back to main screen, he taps "back" button and my navigationController pops back. But when it should pop to the main viewController it fails to restore the view of my initial viewController.
Do you have any clue how to pop back to the first viewController in navigationViewController hierarchy if that view controller has containers with embedded view controllers in them?
Or should I consider changing the architecture of my storyboard?
The fact that the view controllers in a navigation controller have child view controllers is not important. Only worry about the top-level view controllers that are pushed onto the navigation controller's stack. And only push/pop top-level view controllers, not children.
If you are having problems, you are probably doing something wrong, and will need to post a screenshot of your storyboard, along with the code that shows how you manage your navigation controller stack.
If you want your initial view controller to contain the proper subviews, you either need to hide/show what you need to make it to look like you want in viewDidDisappear as the user moves on to a new view, or you need to set it when they come back in viewWillAppear.
However your view is set up when you leave is how it will show up when you come back unless you change it. For example, in your root view controller:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// hide your menu, clean up the view to prepare it for when user pops back
}
OR
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// if menu is showing, hide it. Clean up view before user sees it
}

Bypass UIView without showing

I am using Storyboards for an iOS 7 App. The root controller is a menu. For almost every view, I have a Menu button which brings the App back to that menu using [self.navigationController popToRootController:TRUE]. However, there are two UIView elements where I would like to clear the Navigation Controller view list (as happens when you pop back to the root controller), but then immediately go to another UIView without having the user see the root controller's view. Once at this new view, if the user presses the back button, I want them to go to the menu view.
I've tried to put a performSegue in the viewWillAppear, but it really messes up the Navigation Controller and views. I've tried putting a performSegue in the viewDidAppear, but the user sees first the Menu view flash in, then out on it's way to the correct view.
I hope I've explained this well enough. I hope this can be done.
Thanks.
Your best bet is to build the navigation controller stack yourself, and then use - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated: to replace the current stack.
So you could do something like
...
UIViewController *vcToPush = ...;
NSArray *newVCStack = #[[self.navigationController.viewControllers firstObject], vcToPush];
[self.navigationController setViewControllers:newVCStack animated:YES];
This will add your new controller to the stack using the standard push animation (or not if you so choose), and after the animation is complete, set the view stack to that of the array.

Resources