Posted on by & filed under Content - Highlights and Reviews, Programming & Development.

A guest post by Josh Brown, co-author of Developing an iOS 7 Edge and the Founder and CEO of Roadfire Software, a consultancy that builds iOS apps for businesses. He’s been doing iOS development for almost four years – since the iOS 3 days, and has had the privilege of working on apps for companies of various sizes, from the Fortune 500 to small startups. You should follow him on Twitter @jtbrown.

I’ve been updating apps for iOS 7 in addition to writing a book about it, so I thought I’d share what I’ve learned. If you’re updating apps for iOS 7 (and especially if you’re still supporting iOS 6), read on. I hope you learn something here.

Why Your Views are Hidden Beneath the Status and Navigation Bars (and what to do about it)

If you had an app that was built with the iOS 6 SDK, and recently tried to build it with the iOS 7 SDK, you may have noticed that the tops of your views were hidden by the status bar and navigation bar. You can thank Apple for the translucency effect in iOS 7, where the status bar and navigation bar appear to be translucent. The real problem is that they’ve changed the height of the view – the top of the view on a UIViewController used to be at the bottom of the (opaque) status bar. Or if you had a navigation bar, too, the top of the view was positioned at the bottom of that. Not so any more – Apple wants views to appear underneath the status and navigation bars, especially when scrolling as in a scroll view or table view. Here’s how you can determine the height of those if you’re supporting both iOS 6 and 7:

The respondsToSelector verifies that yes, indeed, we can call the topLayoutGuide method on our UIViewController. We need to do this check since topLayoutGuide is new to iOS 7, so your app will crash if you try to call it on iOS 6. If your target is iOS 7, no need to create a topOfViewOffset method – you can just call self.topLayoutGuide.length in your view controller.

I’m supporting iOS 6, so I’ve added the above method to a category on UIViewController that saves me the trouble of copying it to every single one of my view controllers. I can just import that category and do something like this in my view controller:

Make sure to call topOfViewOffset (or topLayoutGuide) in viewDidLayoutSubviews, not in viewDidLoad. Things are all wacky in viewDidLoad – calling topLayoutGuide.length there returns a big fat 0.

Hide the Status Bar

If you want to hide the status bar, just implement this method in your view controller:

Fixing Broken Table Views

Table views in iOS 7 can’t return 0 from -tableView:heightForHeaderInSection for a grouped table view (UITableViewStyleGrouped). Try switching to a plain table view (UITableViewStylePlain) if you don’t want a header. In iOS 7, both table views appear nearly the same visually, so you’re not out much by switching to plain.

Make sure to nil your delegates and data sources on table views, too. (Thanks to Stuart Hall for pointing this out.)


There’s a lot that is new in iOS 7, and there are a lot of changes to the way things used to work. Updating apps has been a struggle for me – especially in handling the translucent status and navigation bars – so I hope this post saves you some time.

Be sure to look at the iOS 7 resources that you can find in Safari Books Online.

Not a subscriber? Sign up for a free trial.

Safari Books Online has the content you need

Developing an iOS 7 Edge was written by six iOS developers with expertise in the various aspects of iOS 7. The result of this collaboration is a dense ebook focused solely on iOS 7 development (it doesn’t start with iOS 6 info and add on) and backed by the authors’ real-world experience, as well as a working BepBop app that demonstrates how all of the examples work in practice. The introduction of iOS 7 lays the foundation for developing new classes of application, and we hope to show you the way.
iOS 7 Programming Cookbook will help you overcome the vexing issues you’ll inevitably confront when creating apps for the iPhone, iPad, or iPod touch. By making use of new and thoroughly revised recipes in this updated cookbook, you’ll quickly learn the steps necessary to write complete iOS apps using the iOS 7 SDK—including ways to store and protect data, send and receive notifications, enhance and animate graphics, manage files and folders, and take advantage of UI Dynamics.
In iOS 7 Programming Fundamentals, the author backs up the conversation to the C programming language and objective programming so that the reader can really understand why and how objective-c does its job. Next in line is Xcode, which is significantly updated in its 5th version. The author talks about the interface, documentation, and lifecycle of a project. Finally, the book closes out with a look at Cocoa, Apple’s framework for creating apps. The reader will come to understand how the idiosyncrasies of the framework allows for clean, optimized programs.
Programming iOS 7, 4th Edition will help you get a solid grounding in all the fundamentals of Cocoa Touch, and avoid problems during iPhone and iPad app development. With this revised edition, you’ll dig into Cocoa and learn how to work effectively with Objective-C and Xcode. This book covers iOS 7 in a rigorous, orderly fashion—ideal whether you’re approaching iOS for the first time or need a reference to bolster existing skills.

About the author

joshbrown Josh Brown, co-author of Developing an iOS 7 Edge, is the Founder and CEO of Roadfire Software, a consultancy that builds iOS apps for businesses. He’s been doing iOS development for almost four years – since the iOS 3 days, and has had the privilege of working on apps for companies of various sizes, from the Fortune 500 to small startups. He enjoys sharing what he’s learning by speaking at user groups, mentoring one-on-one, teaching classes, and writing on his blog. He lives in the Indianapolis, Indiana area with his wonderful wife and two amazing kids. You should follow him on Twitter @jtbrown.

Tags: apple, iOS 6, iOS 7, Josh Brown, Table Views, topLayoutGuide, translucency effect, UIViewController, views,

Comments are closed.