UITabBar is removed when pushed back on UITableViewController but not ViewController - ios

I have an iPhone app, which has a UITabBar with 5 tabs in it, each of the 5 tabs have NavigationViewcontroller which push to other "sub" views as the user selects different options.
2 of the tabs are UItableViews and 3 are UIviews.
When I push from a UITableView to another uiview, then return to the original UITableView, the tab bar appears white instead of a is original bar with 5 tbs on it.
However if I do the same thing from one of the 3 UIView (which is are the tab bar) to another UIView, then return the tab bar is as fine.
I am using storyboards (for the second time) and I have checked the Atributes inspector in the navigation controller and the root views for the UIView that are working and the table UITableView that are not and I cannot see any difference.
My question is should they be the same?
I also use this code to try and stop the bar from being hidden in the init method of the first view and the tab view,
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed=NO;
}
return self;
Any help or pointers would be greatly appreciated as my reading has left me blank

Use the following way to hide the bottom bar. When pushed it hides the bottom bar and on popping it reveals back the bottom bar
- (void)pushNewViewController{
MyNewViewController *viewController = [self instantiateNewViewController];
viewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController: viewController animated:YES];
}

Related

dismissViewControllerAnimated leaves black screen

I've read a number of threads on stackoverflow about this issue, but none seemed to have a fix that worked for my most basic and straightforward case.
I'm using XCode 7.2.1 and iOS 9.2
I have a class (code shown below) that accepts a UIViewController to use as the presenter of a UINavigationController.
This code below is from ONE class, and it does both the presenting and dismissing.
Starting with screen 1 pictured below, the user taps a button in the upper left corner, which then presents the UINavigationController in screen 2. Finally, tapping the "Done" button in the upper right corner of the UINavigationController (screen 2) causes a black screen... screen 3.
Lastly, you'll notice on the black screen a little red circle with a number in it.
That is from the tab bar in screen 1 at the bottom. For some reason it stacked up all the tab bar buttons in the corner, and left a little area for them to peek out.
-(id)initWithDashboardParentViewController:(TabMapController*)mapVC propertyDelegate:(id<iRpPropertyDelegate>)propertyDelegate
{
self = [super init];
if (self)
{
mapViewController = mapVC;
thePropertyDelegate = propertyDelegate;
}
return self;
}
-(void)displaySpreadsheetOfAllSubitems
{
UIViewController *theContentController;
// Create a generic gridview view controller and initialize it with the data that will be shown.
theContentController = [[iRpGenericGridViewController alloc] initWithPropertyDelegate:propertyDelegate dashboardDataItem:spreadsheetTableData];
theContentController.edgesForExtendedLayout = UIRectEdgeNone;
// Create a navigation controller and embed the content view controller.
UINavigationController *theNavController = [[UINavigationController alloc] initWithRootViewController:theContentController];
// If a detail item was found for this section, then display it in the navigation controller.
if (theNavController)
{
// Set up the 'Done' navigation bar button.
theNavController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(detailDisclosureDone)];
[mapViewController presentViewController:theNavController animated:YES completion:^(void){}];
}
}
-(void)detailDisclosureDone
{
[mapViewController dismissViewControllerAnimated:NO completion:^{}];
}
Well, I did figure out that it has something to do with AutoLayout and the constraints set on my root view controller.
I made a constraint that the root view controller has to be at least a given height, instead of just saying it was 0-nearestSuperview, etc, and now I'm seeing a portion of my view.

Black area with interactivePopGestureRecognizer when popping a view controller with visible nav bar to a one with hidden nav bar

I have this ViewController #1 which is the root view controller of a navigation controller and has
self.navigationController.navigationBarHidden = YES;
ViewController #1 tells its navigation controller to push ViewController #2, which has
self.navigationController.navigationBarHidden = NO;
When I want to go back from ViewController #2 to ViewController #1 by swiping from the left side of the screen, I see my views as the screenshot I attached here. This is captured as I move my finger to the right, so as I keep swiping to the right, the black area on the top right gets smaller and smaller until ViewController #1 covers all the screen area.
I'm guessing that this is caused by the hidden/visible navigation bar difference between the two view controllers.
I'd like to learn if it's possible to get rid of this black area.
As discussed with HoanNguyen, I had put my code to hide/show the navigation bar on viewWillAppear/Disappear but finally I figured out that the trick was to set the values animated. Weird, but this solved my problem and the black area is now gone:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:self.shouldHideNavBar animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:!self.shouldHideNavBar animated:animated];
}
You should put your code set hidden/shown navigation in viewWillAppear or viewDidAppear.

alternating between toolbar / tab bar

my app is structured as follow: UITabBarController > UINavigationController > ViewControllerOne > ViewControllerTwo.
the UINavigationBar has at the bottom the tab bar, now when the user navigates into the second view controller, i want to be able to hide the tab bar and replace is with a tool bar. i tried this code:
[self.navigationController.tabBarController.tabBar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];
when i run the app the tab bar is hidden but the toolbar doesn't appear. plus, since the last VC is a table view controller, when i scroll through the cells there is a white gap between the table and the bottom of the view. how can i fix that?
That won't work because when you hide the tab bar like that the subviews won't be adjusted properly (that's why you get the white space). You'll have to use
self.hidesBottomBarWhenPushed = YES;
In your init method or awakeFromNib... and then
[self.navigationController setToolbarHidden:NO animated:YES];
In the viewDidLoad for example.
That way the tab bar controller's view is going to layout correctly it's subviews when you hide the tab bar. Just remember to call self.hidesBottomBarWhenPushed = NO; in your first view controller otherwise the tab bar is still going to be hidden when the second view controller is popped from the navigation stack.
Try to assigning toolbar with appropriate frame and adding it to self.tabBarController.view

UITabBarController and custom control acting as a tabbar

I have a custom tab bar controller subclass and instead of a tab bar, I use a custom UIView.
The problem is that I cannot get my view controllers to appear. I see a white screen and the "tab" if I call
[super setViewControllers:]
I get really odd artefacts as far as appearance goes.
So instead I tried setting the selectedViewController directly. I've kind of drawn a blank. Any help would be greatly appreciated.
Can you tell me how you are having a custom view for tabs..
Have u removed tabBar & added ur custom tabView.? and keep in mind if remove your tabBar the whole tabBarController will be removed..
So you need to just hide the tabBar from tabBarController and add ur custom UIView in place of tabBar and everything works fine. You have to select the tab index programatically as per the button selection in your custom view.
You can use view Controller containment concept in order to implement custom tabbar.
[self addChildViewController:content]; // 1
content.view.frame = [self frameForContentController]; // 2
[self.view addSubview:self.currentClientView];
[content didMoveToParentViewController:self]; // 3
You can also use my custom control
Custom Tabbar Control

How to handle backBarButtonItem pressed?

I have almost done this in all the application but I have 3 views stacked in navigationController and I need to jump from the third view to the first view.
As I understand I can do this via viewWillDisappear only. But if I try this "jump" I will get the navigationController panel from the second View which with a navigation buttons which cause exceptions/errors.
P.S. Do not advice me to make leftBarButtonitem looking like backBarButtonItem. It is too difficult and I don't know where to find an appropriate image for it.
To my knowledge, you have no choice but to provide your own UIBarButtonItem. You are not permitted from interrupting how UINavigationController works by default. That is, you cannot override the behavior of the back button. You must provide a custom bar button item and set it as the navigation item's left bar button item.
(As a side note, the sort of behavior you're looking for may be an indication of a poor navigation pattern. Back buttons should almost always back out of a navigation hierarchy sequentially.)
Let's say in navigation order your views stacked like top -> 3 -> 2 -> 1 . When you are in this position you can have a flag in your application delegate that shows you will doublePop when backButton pressed as below: ( You are doing this whenever third view appears in the order you mentioned)
MyApplicationDelegate * del = [[UIApplication sharedApplication]delegate];
del.doublePopEnabled = YES;
[del release];
In view 2 :
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
MyApplicationDelegate * del = [[UIApplication sharedApplication]delegate];
if(del.doublePopEnabled){
//Asssuming you have a reference to your navigationController in your view 2
del.doublePopEnabled = NO;
[del.release]
//Use animated as no if you don't want user to see doublePopping.
self.navigationController popViewControllerAnimated:NO];
}
}
Hope it helps.

Resources