Empty navigation bar appearing in subview - ios

I am trying display a UITableView within a larger UIView in an iPad app, mainly because the data is pretty sparse and I'd like to have the table be a smaller area over a background image, rather than taking up the whole screen. The parent UIViewController is correctly set as the table data source and delegate, and the table looks/functions like it should. The whole view is embedded in a navigation controller; the overall UIView shows a navigation bar, as it should, that I can configure normally.
The problem is the UITableView subview also shows blank space at the top for a navigation bar--empty space above the first cell--and I can't figure out how to get rid of it. I know the space is related to the navigation controller, because when I delete the embed link in the storyboard, the space goes away. The table view doesn't present a UINavigationBar property or any other navigation-related properties that I can try to nullify.
I would post a screen shot but I don't have the rep yet.
Can anyone explain where the space is coming from and how to nix it?

I suspect the answer is related to the Top Layout Guide for the view, but I can't diagnose the specific problem.
Here's a workaround from the storyboard: Insert a UIView in the scene, then drag the UITableView into it as a subview. Check the box for the new UIView's "Clip Subviews" in the attribute window, and then use it as a mask, basically, to cover the undesired top margin of the table view. It works and doesn't require any coding, but there has to be a better way.

Related

UIView inside UIScrollerView displays with -64 offset

I'm trying to create a form that will be larger than the screen size and I've decided to use a view inside a scrollerview, then I'm adding the rest of the UI widgets (textfields, buttons, etc.) inside the view.
The view displays and scrolls, but no matter what I try, it displays with a vertical offset of -64 below the navigation controller bar. Once there the view will happily scroll up down.
I want the view to anchored at the top, just below the navigation bar, and then scroll down.
I am using IB.
Lots of time researching and not many answers that have worked for me. UIScrollView seems to be like one of those dirty secrets the whole iOS world seems to avoid....
Thank you for your help.
You can fix this in the storyboard
1- Select the view Controller
2- GO to attributes inspector
3- Uncheck adjust scroll View insets
For your view controller, in the storyboard uncheck the option to extend edges under top bar.

UIView added to ScrollView not fitting full screen with Navigation bar at the top

EDIT: Small update to my issue, what i did as a solution for now was obviously just having my scrollview white. This fixes my issue, but my real curiosity was to why exactly the content view was doing what i explained below. Also still curious to what common practice formatting is when adding a scroll view to a VC with a navigation bar.
So i am a bit confused with what is going on here. I have a VC with a navigation bar at the top and i need to add a Scroll view to it. So when i did that i stretched it to just below the navigation bar at the top of the screen, then added constraints. (I also made the ScrollView background red so i could differentiate it from the content view)
Secondly i added a UIView which i named Content view and i stretched it to the exact same position as the Scroll view. Then added constraints for that as well. (No objects were added yet)
I then ran the app to check how it looked and i noticed that under the navigation bar my there was a big chunk of red, meaning the Scroll view was full screen in the correct position right below the nav bar, but my content view was not.
A couple things i did to fix this was
I extended the Scroll view all the way to the top of the VC, past the nav bar, but when i ran the app i could see red behind the nav bar, which i figured meant it was not right.
I extended just the content view to the top of the VC, but this did not seem right to me either, even though both seemed to fix the problem.
So my questions are:
When adding views in general to a VC with a nav bar at the top should i be extending those views only to the bottom of the nav bar, or all the way to the top of the VC?
I am new to Scroll views as this is my first time dealing with one, am i missing something in this situation? Or doing something wrong?
Your help is greatly appreciated, thank you.
1) Move the scroll view all the way up and beyond nav bar.
2) Have the scroll view match the height of its parent.

IOS/xcode: Tableview does not fill up view when using SearchDisplay

I have several different tableviewcontrollers connected to tabs. All were created in storyboard.
For all but one, I don't have a search bar. For one, however, I do have a search bar. When you view the one with the searchbar the table view does not take up the whole space at the bottom. At the top it shows the search bar as you would expect. But at the bottom, it leaves empty space.
In the measurement inspector for the storyboard, the view controller appears to have the same dimensions 600x600 as the tableview for the other view controllers.
Some answers suggest that the table row height may differ with the search bar controller but I tried changing that and it did not have any effect.
Can anyone suggest what might be causing this problem?

Add a UIImageView to the back of NavigationBar (NOT background image)

I am trying to add a UIImageView to the back of a navigation bar.
The reason is because I want to create a UITableView whose navigation bar is actually a picture (with back button on the left) but I want the picture to scroll with the tableview and when the picture is fully scrolled out. The navigation bar is shown as per normal.
My solution to this problem:
Add a UIImageView to the top of the UITableView and make the navigation bar transparent. Set a contentOffset for the UITableView which is a subclass of UIScrollView so that when the view is presented, it looks like the picture is filling the navigation status bar.
Problem:
If I scroll up, instead of bouncing back, the transparent status bar is shown (with a color of the background as it is transparent).
Possible way to solve this new problem:
I was thinking of trying to limit the ScrollView size to get around with problem but failed.
So I feel is it possible to add the UIImageView to the "back" of the navigation bar so that it is there without any offset? Since that way, my life will be much easier.
Any suggestions on solving this or another new approach to get the same UI/effect?
Related question.
I would do this by adding either a table header or cell at the top of the table which contains your image.
Create the table view so that it extends all the way to the top of the screen. Extend Under Top Bars option. I have not done this with a UITableViewController but I have done this with a UITableView embedded inside a UIViewController's view with the top constraint set to 0 for the view rather than the top layout guide.
Now when you run this your table will fill the whole screen and the top header or cell will be at the top showing your picture.
When you scroll you can either use the UIScrollViewDelegate to detect the movement or implement tableView:didEndDisplayingCell:forRowAtIndexPath:
I'm not 100% sure when you want the navigation bar to go non clear. If its when the image goes off screen then didEndDisplayingCell should be good. If its when the cell bottom passed under the bottom of the navigation bar then scroll view might be your only option.
This will also bounce as you expect when you pull down and it should snap back to the top.
Hope this helps.

Toolbar hiding on rotated UISplitView DetailView

I've based my app on Apple's SplitView project type. I have a TableView as the Master, and am using different types of views as the Detail view. To select types of detail view, I'm using the fancy concept of buttons on my DetailView toolbar. When the DetailView is derived from UIViewController, everything is good. When the DetailView derives from UIViewController, but contains a UITableView then I have problems. In portrait view the toolbar is visible. In landscape mode the toolbar is hidden, even though the Tableview is moved down to allow space for it. The UIToolbar and UITableView are both defined in my NIB file which is loaded to create the detail view. Why is my toolbar invisible in landscape?
BTW, is this the best way to choose Detail view types with UISplitView? Bonus question, what if selecting a row in my DetailView tableview should bring up another View, I can't push it like I would with a NaviagtionController, so how do I go back to the detail tableview?
Thanks, Gerry
HI Gerry,
I have faced the same toolbar problem, when trying to rotate the splitView, toolbar will disappear. If you are creating the toolbar in the interface builder, try to set the toolbar properties(size), by selecting the toolbar, then --> Tools -->Size inspector, in the autosizing section, mark the left, right and upper red lines and unmark the bottom red line, then everything will works fine.
-Maria
Bonus question, I would create a UINavigationController in code, set it's rootcontroller to the DetailView tableview (self) and then push the new view on top of it.
When you react to the rotation change are you using the same view or a different one for the detail view? Seems like the new view may not contain an instance of the toolbar? Or the Tableview is covering it up because the landscape view has less vertical room than the portrait view. Are you resetting the height of the tableview to allow space for the toolbar within the 768 height when rotating to landscape?
Just a tip but whenever I run into odd things like this I remove the elements from the NIB file and create them programmatically in code and it usually solves the problem. You get a lot more control over things when you do. Overall as I've gained more experience with programming for iPhone OS I've found that I rarely put much into a NIB file any longer and do almost everything in code now.

Resources