Web Apps. Mobile Apps. Awesome!


View Hierarchies and iOS 6

September 18, 2012

While testing our app for iOS 6, Punk or Metal, I ran into an interesting bug. Every screen displayed exactly as it had in iOS 5 but whenever the one view with a table was to be shown (for comments or news), the app crashed with the following error:

'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view 
controller at a time! View <UITableView: 0xba93400; frame = (0 0; 320 480); clipsToBounds = YES; 
autoresize = W+H; gestureRecognizers = <NSArray: 0xa9a8f10>; layer = <CALayer: 0xa9a8b50>; 
contentOffset: {0, 0}< is associated with <UIViewController: 0xa982a00>. Clear this association 
before associating this view with <NewsCommentsView: 0x895b810>.'

It sounded pretty reasonable, there was some kind of view hierarchy problem. So… I did what I always did, hit StackOverflow and ran a search.

And all I heard were crickets.

There was a bunch of stuff about how Apple was cracking down on the relationships between controllers and child controllers but none of it applied directly to what we were encountering.

Google was equally as unhelpful. And most of it was in German anyway.

So what was the problem?

Believe it or not, once I figured it out, the problem was perfectly explained in the error log. And it was a total “new to iOS” programming mistake.

Can you spot the problem?

Our comments and news view, conveniently called NewsCommentsView, was a UITableViewController child and had a nib it was expanding and exploding when it expanded. The image to the right shows the view hierarchy as it existed. Can you spot the problem?

If not, then the answer lies in the log message “associated with <UIViewController: 0xa982a00>. Clear this association
before associating this view with <NewsCommentsView: 0x895b810>

Essentially, it’s saying that there’s an anonymous UIViewController already associated with the UITableView that needs to be cleared before it is attached to NewsCommentsView. And that would be the View Controller shown in the nib hierarchy to the right.

It took a little bit of playing around to figure this out but when I explored the connections between the Table View and the actual NewsCommentsView controller, I realized that everything was pointing from File’s Owner to the Table View with nothing linking to the anonymous table view controller except for the fact that the Table View was its child.

Thus… by simply deleting the the extra controller from the hierarchy, the problem was solved. No more crashes and no more problems.

I realize this may seem a bit anti-climatic but while working in iOS, I’ve often found it’s the small things that have surprised me while the big things just managed to pretty much work themselves out.

And so that’s the story of how this boy from California solved the only issue that seemed to have appeared between iOS 5 and 6.

By the by, Punk or Metal is due out really soon. But if you need a fix now, be sure to visit out Facebook page, like it, and add your own thoughts to the photos we’ve been posting.

Back to Blog

42 Tags: , , , ,


Content for class "bottomYellow" Goes Here
Content for class "bottomBlue" Goes Here

42 Solutions

Working with 42 Solutions, you’ll find that it’s not the technology that’s important, it’s the idea. Regardless of whether your company is based on proprietary software or open source, we will find the right tools to get the job done.

Invite us to your office and we’ll send a pair of consultants armed with laptops and bright ideas, ready to solve your problem and offer solutions. We pride ourselves in getting to know how you do business and integrating into your process.