Click here to Skip to main content
15,885,767 members
Articles
Tip/Trick
(untagged)

Bug in XCode 6.1, Vertical Gap Above UITableView

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
11 Dec 2014CPOL2 min read 14.4K   1   4
How to fix an issue with a vertical gap appearing about UITableView, embedded in a UIViewController

Introduction

I'm not a fan of XCode.

We're almost in 2015, and it continues to be a nasty little outdated development environment to work in, and it just doesn't seem to get any more stable with each release.

Below is a nasty bug I've encountered which burned away 2-3 hours of my day yesterday.

iOS Storyboard Bug

Here's the issue.

I had a UITableView, embedded in a UIViewController, but I couldn't get rid of the large vertical gap above it.

Image 1

The strange thing about this issue is that, when this screen first appeared, the cells would appear as above (with the gap above them), and if I swiped up and down, the scrollbar would just appear next to the UITableView's cells shown here.

However, when swiping, I could actually scroll the cells into that blank area at the top. So, above, "Mikes Company" would then happily scroll into that gap area, even though the scroll bar appeared lower, in the area below this vertical gap.

If you Google this issue, you'll find lots of suggestions about adding code like this:

self.automaticallyAdjustsScrollViewInsets = NO;

tableView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);

tableView.separatorInset = UIEdgeInsetsZero;

But, no, these didn't work for me.

I spent ages desperately trying to fix the issue because, being new to AutoLayout, I felt sure that I'd missed something. Surely I must have a constraint in the wrong place?

No.

The solution was more ridiculous than that.

I needed to go into the Storyboard, and drag my TableView so it was no longer the first subview of my UIViewController screen.

Image 2

Once the UITableView was moved to the second position, the screen worked perfectly.

And that's it.

Hopefully, this short article will save some other XCode victims from falling into this bug, errr, feature.

If anyone needs me, I'll be in the bar, drowning my sorrows.

 

A week later..

I was wrong.

This bug/feature doesn't just happen with UITableViews.

Today, I had an identical issue, this time with a UITextView.  It also started appearing on my iPhone app with a large vertical space above it.

Image 3

Once again, I went into XCode, had a look at this screen in the Storyboard, and sure enough, this control was the first subview of my view.

(Incidentally, in the Storyboard, my constraints were all set okay.  If I selected "Editor \ Resolve Auto Layout Issues \ Update Frames", then the controls all stayed put...)

Just as with the UITableView issue before, I dragged the "Text View" into second place in the list, and the issue went away.

Image 4

(Sigh.)

 

 

 

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Switzerland Switzerland
I'm a C# developer, working in finance in Zurich, Switzerland.

Author of the PartnerReSearch iPad app, which was a winner of a "Business Insurance Innovation Award" in 2013, and a TechAward2014 "Innovation of the year" award in 2014.

Objective-C is the 2nd hardest language I've ever learned, after German... Wink | ;-)

Comments and Discussions

 
QuestionThank Pin
haibtdt2-Jul-15 0:32
haibtdt2-Jul-15 0:32 
AnswerRe: Thank Pin
Michael Gledhill2-Jul-15 2:36
Michael Gledhill2-Jul-15 2:36 
GeneralThanks Pin
Member 113562706-Jan-15 4:37
Member 113562706-Jan-15 4:37 
GeneralRe: Thanks Pin
Michael Gledhill6-Jan-15 4:43
Michael Gledhill6-Jan-15 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.