Why is my UITableview Y origin changing based upon the position in TabBarController - ios

Upon clicking the button on the first screen the user is presented with view controllers contained within a tab bar controller. The view controllers have two tableviews in them, the first a top static table and a second table just below. The view controllers in the tab bar controller that are not within the "more" display correctly. If I go to "more" and select a view controller the view is displayed with the top cell pushed down.
If I go to the "more" screen, click edit, and move the order of view controllers in any way, view controller displayed through "more" display correctly. Upon leaving the "more" section the top table cell (top table) is not displayed.
It seems reasonable to me that there is an issue in the UI or storyboard, however nothing jumps out at me as the issue. I've tried both manually setting constraints and also using suggested constraints.
This sample project is available at https://github.com/propstm/NavigationStructureTest

I simply updated the constraints in the Two Table VC , then the issue was not there.

Disable Size classes,and delete the constraint(top tableView) of "vertically space to top layout guide",add pin top space to super view can solve the problem.
Maybe it's a bug of Xcode,see this.

I think it has something to do with the "more" controller provided by the TabBarController having its own navigation controller, and your storyboard set up to extend edges beyond top bars.
Although you are trying to hide the navigation bar, I think its done in the wrong place and should only be required when the item is being presented in the "more" controller. The way its currently implemented confuses the top layout guide, which seems to be left assuming there are two top bars even though one of them is hidden.
I was able to fix your demo project in two ways. By either:
1) Update the storyboard and turn off "extend edges" on the tab bar (and set the tab bar and top bars to be opaque):
OR
2) Simplify the viewWillAppear/Disappear and viewDidAppear/Disappear methods and hide the navigation bar when within the tab bar more controller:
- (void)viewDidAppear:(BOOL)animated{
//self.navigationItem.backBarButtonItem.title = #"HOME";
self.tabBarController.title = #"Entity List";
//Pretty activity indicator
[self.topTableView reloadData];
}
- (void)viewWillAppear:(BOOL)animated {
if (self.navigationController == self.tabBarController.moreNavigationController) {
[self.tabBarController.navigationController setNavigationBarHidden:YES];
} else {
[self.navigationController setNavigationBarHidden:NO];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController.navigationBar setHidden:NO];
}
- (void)viewDidDisappear:(BOOL)animated {
}
This ensures the top navigation appears correctly without messing up the layout guide.

Related

ViewController in separate storyboard using RBStoryboardLink has extra 20px black status bar when hide navigation bar

I tried using RBStoryboardLink to separate storyboard in my project, and in one of the storyboard, I have an initial view controller which is embedded in navigation controller,and I use [[self navigationController] setNavigationBarHidden:YES animated:NO]; to hide navigation bar.
However it will introduce a 20px black area in status bar as below
I have tried options such as uncheck extend edges under top bars or uncheck adjust scroll view insets but nothing works so far.
anyone has any clue how to resolve this issue?
Thanks.
Ok, I managed to find a solution for my case.
The key is _needsTopLayoutGuide
I customised another called RBStoryboardNoNavLink and set _needsTopLayoutGuide to NO in that class, and if the storyboard link is a tab child view controller and do not want navigation bar (or do not embed in navigation controller even), can just rename that class to RBStoryboardNoNavLink and it works perfectly for my case.

add a view under tabbar in storyboard

I'm wondering if there's a way (preferably an easy one) to add a view under the tab bar, like shown on the attached picture, so that it stays there when I switch between tabs and when new view controllers are pushed/popped on each tab.
I have subclassed UITabBarController as "MainTabController" and set is as the custom class for the Main Tab Bar Controller Scene in my storyboard. Then in MainTabController's viewDidLoad I move the tabBar up and add the red subview. So far so good, but the main view area size is still like it was before, with the tab bar at the bottom, so now the last few elements of the table stay below the tab bar.
I would very much like to avoid adjusting the frame size for each and every controller I push into either of the tabs, so I hope that there's a simpler solution that I'm not aware of.
You can do this by embedding your tab bar controller in a custom container controller. You can do this in a storyboard by making a UIViewController the initial view controller, and adding a container view to it. Size that container view so it has whatever space you need underneath, and add your view in that space. Delete the view controller that comes automatically embedded in the container view, and control drag from the container view to your tab bar controller, and choose "embed".
Be aware that there's a bug in the way tab bar controllers layout their views in iOS 7. If you put a view near the bottom of one of the controllers, it will appear the first time you see it, but move down under the tab bar when you select another tab and then come back again (it will reappear if you rotate to landscape and then back again). You can get around this bug by making your container view controller (the initial controller in my storyboard) the delegate of the tab bar controller, and adding this code.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // called by the embed segue
UITabBarController *tbc = segue.destinationViewController;
tbc.delegate = self;
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[tabBarController.view setNeedsLayout];
}

Tab Bar Controller - Show a view controller that is not one of the tabs

I wonder if this is possible. The design for this app I am working on is as below:
Two sliding views sit one on top of the other. The bottom view is a 'Settings' view. The top view is a tab bar view. We are using ECSlidingViewController for the sliding.
When the app is opened for the first time, the tab bar view shows with first tab selected.
When they tap on the hamburger menu or slide right, the bottom, settings view slides into view.
When they tap on an item in the settings view, like the About item, the corresponding view should be displayed inside the top tab bar view with none of the tabs shown as selected.
I think I am going to have to convince my team to not display the settings items inside of the tab bar, it seems just too twisted. But just wanted to know if anyone else has done anything like this and if it is possible to do it without introducing too much complication in the code.
I've done something with the same design with a menu that slides from the left and over the tab bars. I ended up putting a View Controller on top of everything else
Something like
[self presentViewController:AboutViewController Animated:YES];
Just make sure that you either put that view controller in a UINavigationController or something with a dismissViewController for users to return to your main page.

Navigation title not showing on view with tab view controller, but "back" navigation works

I'm relatively new to iOS Objective-C development, and I've come across a problem that I can't find a solution to.
I have a Table View Controller, with two prototype cells on it, which populate fine. This Table View Controller is one of three Tab Views, and the View that sends to the Tab Views has a Navigation Controller. This means that the views within the Tab Views also have a Navigation bar. The bar works fine, in terms of the "back" button working as expected, and the bar being in position. However, (at least on the List View) the Navigation Bar isn't fully recognised - it's title doesn't appear, and the table cells start directly below the status bar, rather than below the navigation bar.
Here's a couple of screenshots showing the problem:
what appears in Xcode (what I expect to happen)
And then on the device, this is what actually appears - the Back button in place and working fine, but no title field, and the table cells start too high.
I've tried adding Navigation Bar's and Navigation Items, and while adding a Navigation Item allows me to put a title on in Xcode, it still doesn't appear on the device in testing. I also tried to add another Navigation Controller just before this view, but that didn't resolve the issue either, and it caused navigation problems further down in the heirachy.
Hope I've been clear enough, please say if I need to post more information - I'm relatively new to Xcode and so not sure what exactly is applicable and what isn't. Thanks!
please try this code, it might fix your table position
// Since in iOS7 the nav bar is translucent by default, so the table view starts at (0,0)
// you can either disable the translucent, which i don't recommend unless you really want to
// or just add 64 pixel on the top of your table view
[self.YOURTABLEVIEW setContentInset:UIEdgeInsetsMake(64, 0, 0, 0)];
and for the title, please try this
self.tabBarController.navigationItem.title =#"YOUT TITLE NAME";
Hope that helps..
Assuming your hierarchy as
NavigationController -> ViewController -> TabBarController -> ViewController1
-> ViewController2
-> ViewController3
If you want to hide navigation item in viewcontroller1, Add the following line
self.navigationController.navigationBarHidden = YES;
If you want to show title in viewcontroller2, Add the following line in
self.navigationController.navigationBarHidden = NO; //add this if you hide navItem viewcontroller1
[self.parentViewController.navigationItem setTitle:#"Title"];
If you want to hide backbutton and show title in viewcontroller3, Add the following line
self.navigationController.navigationBarHidden = NO;
[self.parentViewController.navigationItem setTitle:#"Contacts"];
self.parentViewController.navigationItem.hidesBackButton=YES;
Add this lines to viewdidAppear method instead of ViewdidLoad ,if you have problems inshowing when switching tabs.
I had the same problem, but what I did to create this problem was that my buttons action was connecting to the actual table itself and not the table Controller. I removed the modal action and created a new action to the table controller and it fixed the problem.
Try to click the Navigation Bar from your storyboard or nib.
Then add your title to the property.

TabBarController - switch tab keeping banner view;

I have a TabBarController with four view controllers . In my first view controller i have the following two methods:
-(void)loadclistview
{
[self.tabBarController setSelectedIndex:2];
}
-(void)loadglistview
{
[self.tabBarController setSelectedIndex:1];
}
I use them to change the view form one tab to the other. But changing tabs this way doesn't preserve my banner view, it does not load the banner into the new view controllers (tabs). If i change tabs using the tab bar , all the views load banners correctly.
Pls help me here - i don't know why this is happening , and what should i do to switch tabs through selectors so that the banner will load in the new views.
EDIT:
I solved it by adding the current bannerview as a subview to the selected viewcontroller from the tab bar ; like this:
[self.tabBarController.selectedViewController.view addSubview:_bannerView];
I saw this also works to adding the bannerview to subsequent view to a navigationcontroller - like showing the banner in child views of the main view which constitues a tab;
[self.navigationController.view addSubview:_bannerView];
Adding the subview this way is fine, but you also have to handle the show/hide of it when there is or isn't an iAd, and the resize of the content view to make room for displaying the subview. The TabbedBanner project in the Apple iAdSuite sample has a nice encapsulation of this functionality.

Resources