UITableView not showing through Navigation Bar - objective-c

I have a UITableView as a subview of my custom UIViewController. I want to position it beneath the navigation bar, and when I scroll it I want it to be visibile in a translucent way through the navigation bar. To do this I should set the y of the table view to zero and set the property edgesForExtendedLayout to UIRectEdgeAll; in this way the things should work, because the UITableView should be set right beneath the navigation bar.
I have a big problem: if I set the y position to zero, the table view is positioned under the navigation bar, and the first part is partially hidden below the translucent bar. Also, if I set the y position to the height of the navigation bar, the table view could never be visibile through the navigation bar, because it starts from beneath the navigation bar.
Actually things work for UICollectionView, the y position is set to zero and when scrolling I can see the UICollectionView through the navigation bar.
Any suggestion about the problem? Is this an iOS 7 bug?

set the origin of the UITableView to 0 as you had and then its contentInset using the topLayoutGuide of the UIViewController.
That will probably look like this
self.tableView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 0, 0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 0, 0);

Related

iOS 7 tab bar shown in wrong position

iOS 7, the tab bar does not appear in the bottom of the screen.
I am just using a Tab Bar Controller in my StoryBoard.
Update: I tried to set is location at the top of the screen programmatically (code below), it was correctly positioned there (at the top)
UITabBar* tabBar = self.tabBarController.tabBar;
tabBar.frame = CGRectMake(0, 0,
tabBar.frame.size.width,
tabBar.frame.size.height);
But when I tried to set it at the bottom (code below) the bar totally disappeared!
UITabBar* tabBar = self.tabBarController.tabBar;
tabBar.frame = CGRectMake(0, self.view.frame.size.height - tabBar.frame.size.height,
tabBar.frame.size.width,
tabBar.frame.size.height);
Any help?
Thanks.
I know I should not answer my question but the solution is actually simple (After 1.5 hours of headache):
My tab view was part of a bigger project that already had a navigation controller that includes a tabBar. So all what i did is hiding this original tabBar so that mine can take its position.
Just this line:
self.navigationController.toolbarHidden = YES;

Delete the grey bar at the bottom of the UIView

Why does all my UIViews have a grey bar at the bottom. I can hide it in runtime with the code self.navigationController.toolbarHidden = YES;
But I need it hidden in development mode. I have tried changing the navigation controller properties to bottom bar = non, did nothing.
How can I get rid of this grey bar at the bottom in development mode?
Select your navigation controller and open the attributes inspector. Make sure the Bottom Bar property is set to None.
You can also do the same for individual viewControllers.

Hiding Nav Bar moves view "up"

The usual story -- I'm making an iOS 5/6 app run under iOS 7 and the navigation bar behavior change is causing a problem.
The app already worked like the iOS 7 default with a full-screen view and a translucent nav bar "over" of the view. The problem is that hiding/un-hiding the nav bar causes different behavior in iOS 7. On iOS 5/6 hiding/un-hiding the nav bar does not change the view. On iOS 7, hiding the bar visually moves the view up leaving a blank bar at the bottom of the screen and un-hiding the bar moves the view back down to occupy the full screen (with the nav bar on top, of course).
I need to continue to support iOS 5 so I don't use auto layout, but I do use the full screen.
I have a view in which I'm viewing a zoomable image -- so the view controller has a fullscreen view containing a scrollView which contains an imageView.
The status bar is always hidden.
I get to the view controller via a navigation controller so there is a (black, translucent) navigation bar which lies over the top of my fullscreen view/scrollView/imageView.
After a brief delay some overlaying labels fade and the navigation bar is hidden
A single tap restores the overlay labels and un-hides the navigation bar.
This works on iOS 5/6 -- the navigation bar slides off the top of the screen uncovering the top of the view/image.
On iOS 7, when the navigation bar slides off the top of the screen the entire view visually moves up a corresponding amount (i.e. 44 points) leaving a black bar at the bottom of the screen. I can see this by setting a background color on the top-level view and resizing the scrollview enough to see the background; the top of the view does indeed move offscreen and the background color is not drawn over the bottom (44 points) of the screen.
BUT, self.view.frame doesn't change and remains at {0, 0} 320 x height.
When I single-tap to restore the overlay info and navigation bar the view moves back down to occupy the full screen and the translucent nav bar is over the top of the view/image.
Nothing I've tried changes the behavior:
Changing the IB view controller layout controls (Under top bars, Under bottom bars, Adjust scroll view insets). Building for 5.1, 6.1, and 7.0 all produce the same result when run under 7.0.
self.edgesForExtendedLayout = UIRectEdgeNone
does nothing. Using the layout delta values doesn't do anything. In IB the view looks the same when "viewed as" iOS 7 and iOS 6 and earlier. I print out a lot of debug info but nothing about the view (or scroll view) seems to change when the view moves "off screen".
The code that shows the overlay info (run when the view is first shown and on single-taps) is:
- (void) showOverlayInfo {
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
[[[self navigationController] navigationBar] setTranslucent:YES];
[[self navigationController] setNavigationBarHidden:NO animated:NO];
overlayInfoHidden = NO;
overlayInfoFading = NO;
self.infoButton.hidden = NO;
self.infoButton.alpha = 1;
self.descriptionLabel.hidden = NO;
self.descriptionLabel.alpha = 1;
}
The code that hides the overlay info is:
- (void) hideOverlayInfo {
overlayInfoHidden = YES;
overlayInfoFading = NO;
self.infoButton.hidden = YES;
self.descriptionLabel.hidden = YES;
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
So can anybody tell me what (presumably simple) thing I'm missing?
I finally found my problem.
The key fact is that the image-viewer view controller was in a UIPageViewController,
so what I was looking at and experimenting with was really "inside" another view controller.
Although I had disabled the view controller setting Adjust Scroll View Insets for the image viewer VC, I hadn't done it for the containing VC that created the UIPageViewController and the UIPageViewController presents the pages in some subclass of a UIScrollView. When I changed them for the parent VC, the problem vanished.
So I think the moral of the story is to:
Think about the problem more globally when local doesn't work because maybe you're missing some important context.
If you don't want to use the iOS 7 behavior, change the settings for every single view controller you have!

How does UIViewController's automaticallyAdjustsScrollViewInsets work anyway?

self.automaticallyAdjustsScrollViewInsets = YES;
I set that to yes. I think it's yes by default.
Then when I check the inset this is what I got:
NSStringFromUIEdgeInsets(self.tableView.contentInset): {0, 0, 0, 0}
I thought it should be set up in a way that incorporate the navigationBar and statusbar. So what happened?
From what I know
automaticallyAdjustsScrollViewInsets
allows the view controller to adjust its scroll view insets in
response to the screen areas consumed by the status bar, navigation
bar, and toolbar or tab bar
works on the view which is direct subview (someone says it must be
the first subview) of the View Controller 's view
this view must be a ScrollView subclass
the View Controller is embedded in Navigation Controller or TabBar
Controller
edgesForExtendedLayout is UIEdgeRectTop (if you want the ScrollView
subclass view to be behind the top bar), UIEdgeRectBottom (if you want
the ScrollView subclass view to be behind the bottom bar)
The code below replicates what automaticallyAdjustsScrollViewInsets does when edgesForExtendedLayout = UIEdgeRectTop
self.scrollView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 0, 0);
self.scrollView.contentOffset = CGPointMake(0, -self.topLayoutGuide.length);
I think it depends on your UIVIewController's edgesForExtendedLayout value. If you want content to appear AFTER top, set edgesForExtendedLayout' = UIRectEdgeNone (or UIRectEdgeRight | UIRectEdgeLeft | UIRectEdgeBottom, you just don't want to includeUIRectEdgeTop`)

Difficulties Re-positioning TableView in Xcode

I have an application in Xcode 4.5.2 that uses storyboards. I have a table view, and I want to reposition the table view so that it is a bit lower on the screen so that I can add an image and a button above where the table view starts. I have researched this question and although I have found a couple of suggestions, none have worked for me yet. The table view is accessed via a modal segue, so there is no navigation bar.
Here is what I have already tried:
1) I added a navigation bar and set its background to my image and then tried to add the button into the nav bar. Because Xcode would not let me resize the nav bar, my image was distorted as was my button and so I abandoned this effort.
2) I added a tool bar but had similar issues as I did with the navigation bar.
3) I attempted in code to move the table view down (thinking I could add the image and button in the free space above the table view). This did not work at all, my table view origin remains at the very top of the screen. but here is the code:
//called in the view did load method of the table view controller class
- (void)repositionTableView
{
float yOffset = 75.0;
CGFloat x = self.tableView.frame.origin.x;
CGFloat y = self.tableView.frame.origin.y + yOffset;
CGFloat height = self.tableView.frame.size.height;
CGFloat width = self.tableView.frame.size.width;
CGRect newTableFrame = CGRectMake(x, y, height, width);
self.tableView.frame = newTableFrame;
}
Can anyone give me any suggestions on how to approach this problem? Thanks.
Make sure:
You created a UIViewController.
UITableView is the subview of self.view.
Autolayout is disabled.
And you can move it freely.