‘UIViewControllerHierarchyInconsistency’, reason: ‘A view can only be associated with at most one view controller at a time!

So I was working on an iOS app for a client and received this error when trying to launch the app in iOS simulator. I was assured that the repository I was pulling from was the same codebase as the app currently in the store. After googling, I found several stackoverflow questions on this with a lot of text answers and 1 with a very short explanation with a before and after screenshot that didn’t explain much. As you can tell by the blog URL, iOS is currently not my programming strength, so I decided to make a blog post to go slightly deeper into this and compile the bits I learned from debugging this.

First of all, the reason I encountered was due to a change introduced in iOS 6. I forget what it was exactly but that’s why we’re seeing this error message.  What error message? Something that looks like this:

2013-07-12 11:07:52.775 App[3545:c07] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <UIScrollView: 0x89780c0; frame = (0 20; 320 548); autoresize = W+H; gestureRecognizers = <NSArray: 0x8979730>; layer = <CALayer: 0x89782c0>; contentOffset: {0, 0}> is associated with <UIViewController: 0x8979cc0>. Clear this association before associating this view with <RootViewController: 0x753ed50>.'
*** First throw call stack:
(0x172b012 0x1110e7e 0x172adeb 0x481cb9 0x518f7c 0x515440 0x845be 0x840e7 0xaeb58 0x651019 0x1124663 0x172645a 0x64fb1c 0x5147e7 0x514dc8 0x514ff8 0x515232 0x5154da 0x52c8e5 0x52c9cb 0x52cc76 0x52cd71 0x52d89b 0x52edc6 0x52f065 0x52f1a8 0x52f5b9 0x52f257 0x52f1de 0x11bfd 0x15c589 0x15a652 0x15b89a 0x15a60d 0x15a785 0xa7a68 0x1a38911 0x1a37bb3 0x1a75cda 0x16cd8fd 0x1a7635c 0x1a762d5 0x1960250 0x16aef3f 0x16ae96f 0x16d1734 0x16d0f44 0x16d0e1b 0x20657e3 0x2065668 0x433ffc 0x1fdd 0x1f15)
libc++abi.dylib: terminate called throwing an exception

So we, obviously, have the title of this article:

'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time!

followed by the important part:

<UIScrollView: 0x89780c0; frame = (0 20; 320 548); autoresize = W+H; gestureRecognizers = <NSArray: 0x8979730>; layer = <CALayer: 0x89782c0>; contentOffset: {0, 0}> is associated with <UIViewController: 0x8979cc0>. Clear this association before associating this view with <RootViewController: 0x753ed50>.'

This is telling us a few things:

  1. The main issue is in RootViewController
  2. UIScrollView and UIViewController are in some sort of Highland/ThunderDome situation

    Highlander: The Game
    Highlander: The Game (Photo credit: Wikipedia)

So we should open up the problem file:

full view

Hey! Look, there’s the ViewController and something called Scroll View. We’re probably on the right track. It’s right there, under Objects. Let’s take a closer look at that.

 

 

 

 

 

 

issue

 So what iOS 6 is complaining about is we have a view within a view in our view controller (kinda like Inception).
So what do we have to do to solve this? Let’s take the Scroll View child and make it a sibling.
solution
Well now that View Controller is kinda useless, let’s clean that up.
cleanup
Oh yeah, I read something about the File’s Owner Class, so let’s change that too. I’m putting a pic in of this because it’s a change I made and I’m not sure if it actually has anything to do with this but figure I’d rather have too many steps than not enough steps.

file owner classThere you have it. That’s my how I solved this issue. Hope it works for you. Hopefully someday, I can come back to this and give a more thorough explanation but for now, this is all I got.

Enhanced by Zemanta

0 comments on “‘UIViewControllerHierarchyInconsistency’, reason: ‘A view can only be associated with at most one view controller at a time!Add yours →

Leave a Reply