Subview UITableView in Xcode 5 without NavigationBar gap - ios

I am trying to add a UITableView (TV) as a subview in one of my xibs, and this TV include a SearchBar at the top. After I have setup my xib so it looks correct I try running the simulator, however the TV seems to be leaving a gap at the top to allow for the UINavigationBar (see screenshots below):
Can anyone advise me on how to overcome this issue, I am running in to a lot of issues in Xcode 5 which I did not have before when setting up nibs.
Thanks for any help.

If you use storyboard and drag a tableview inside an UIView embedded inside a Navigation controller Xcode automatically considers the space for the navigation bar.
if not add constraints. for a tableview you need 4 constraints:
Leading
Trailing
Top space
Bottom space
to add constraints select the tableview and go to editor->pin and select them

Related

UISearch layout is different on different iPhones

On my storyboard, I add a UISearchBar and below that I added a table view. On iPhone 8, I am seeing the UISearchBar right below the navigation bar/header and on iPhone 5s and on iPad and I seeing some space between navigation bar/header and the UISearchBar.
Image showing iPhone 5s on left and iPhone 8 on right:
UISearchBar on ViewController on the storyboard
UITableView on ViewController on the storyboard
Constraints on that view
Any idea what could be happening?
EDIT:
I tried wrapping up both search bar and table view in UIStackView and added constraints around UIStackView so I don't have to add constraints for search bar and table view, but this time the search bar doesn't show up at all on the screen.
Screen with UIStackView
Did you check it without UITableView?
Maybe it changes its position only seemingly?
Go to simulator -> window -> unmark 'show device bezels' and add 'pixel accurate' ( cmd + 2)

XCode 7 and iOS 8 Auto Layout top constraint issue

I recently updated my XCode 6.3 to 7 and strange things started to happen with my auto layout constraints in the storyboard.
My app uses UITabBarController with three tabs. The initial tab has a UICollectionView with top constraint set to 44px from the top layout guide (there is a toolbar in the embedding UINavigationController.
When I run the app on iOS 7.1 (iPhone 4), everything looks fine. The collection view doesn't go bellow the toolbar. However in iOS 8.4 (iPhone 6) the collection view goes bellow the toolbar UNLESS I switch tabs and go back to the first one, where the collection view is positioned where it should be.
What I did:
Unchecked all "Extend edges under...." for every view controller in the chain
Set all simulated metrics for Status/Top/Bottom bars to "None" in every view controller in the chain
I had the idea to check for #available(iOS 8.0, *) and extend the constraint constant +20 pixels. But when I switch back to this tab, the collection view goes 20 pixels lower than where it should be.
So, I guess something happens to the view controllers when I switch tabs. What is it? Or is there any solution. I'm on a deadline and this is the only problem I have with my app.
p.s. I can provide source code and XCode screen shots if needed. But still, I think it's something more theoretical, than practical.
1) click on your UITabBarController in storyboard->identity inspector
2) uncheck "Adjust Scroll View Insets"
repeat for individual view controllers inside UITabBarController
Sometimes this happen also to me. I suggest replacing the top layout constraint with an height constraint equal to the view of the ViewController, this resolved my problem.

Programmatically add UISegmentedControl in UIToolbar below UINavigationBar

I'm trying to get this to work on iOS 7 and 8+.
In loadView of the viewController, I add a UISegmentedControl, along with flexible spaces, as items to a UIToolBar. I then add the UIToolbar as a subview to the main view, setting the vertical position to be the height of the navigation bar.
First problem. The UISegmentedControl is vertically off center so the top of it, is cut off.
Second problem. Rotating to landscape messes it all up. Specifcally, the UIToolbar seems to move underneath the navigation bar whereas the UISegmentedControl doesn't.
Autoresizing issue? I've tried various settings and can't seem to get it to center vertically within the UIToolbar.
It could be that your UIToolbar constraints are not set properly and also that there is no flexible space around the segmented control. Here's a link to a storyboard file I made that have proper constraints and flexible space, tested to work.
Preview:
Here's the Storyboard file: http://www.filedropper.com/main_4

Autolayout doesn't work?

So I'm creating my app in storyboard, and i'm using an navigation controller, added an add view, and trying to auto layout stuff there.
But the problem is, i only get blue guided lines when I'm near the corner left and right. So it's basically not looking at my Navigationbar above.. and just ignoring it.
Also, when I'm switching the simulator to a 3.5 inch (I'm making it in 4 inch) the buttons and labels will disappear underneath it. And they are added to Auto layout blue lines?
The blue lines are not AutoLayout, but just lines that guide you when placing your views. Auto Layout only comes in when you start adding constraints. Check out Apple's Autolayout guide:
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/Introduction/Introduction.html
Control drag from the label to the navigation bar and it will show the below window. The first option is for you to create the constraint from the Navigation Bar bottom.
The Top Layout Guide is a iOS 7 specific feature which marks the bottom line of the navigation bar. The total height of the navigation bar (if present) plus the height of the status bar (if present) equals the toplayoutGuide.length

In iOS 7, how do you access the topLayoutGuide / bottomLayoutGuide in Interface Builder?

Using XCode 5, downloaded today. iOS 7. When I run app the table view header appears underneath the navigation bar, I don't mind it scrolling underneath the navbar but I'd like for it to appear unobstructed initially. I am trying to figure out how to use the topLayoutGuide mentioned in the iOS 7 transition guide, which says you can set a constraint relative to it, but doesn't explain how.
Anyone know?
Transition guide here:
http://tinyurl.com/mgdl4sg
Just realized that my storyboard was still set to XCode 4.6
You have to go to the File Inspector (icon that looks like a file icon in the right navigation panel in Xcode) and then under "Interface Builder Document" where it says "Opens in" change to Default (5.0) and / or "View as" iOS 7.0 and Later
Then your IB document will show the guides inside the left hand navigation panel under the view controller
Often if you select the view, and click the "Pin" button at the bottom right, pin the vertical spacing, and the dropdown will have an option to use the topLayoutGuide
In my Storyboard, was still have trouble getting my UITableView to pin the vertical spacing between the top of the table view and the top layout guide. Every time I control-dragged I would get it pinning to the bottom of the table view instead of the bottom. But then I tried manually dragging the table view so that it appeared below the nav bar in IB and then control-dragged and the vertical spacing finally worked.
I had the same problem, and in Storyboard when I set the top bar to Opaque the top of the scrollView changed so that it wasn't obscured by the nav bar. Makes sense, but it's unfortunate that you can't use a translucent nav bar and get the same effect.

Resources