Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Stephen Hancocks
Stephen Hancocks
9,271 Points

View is not in the window hierarchy

I'm revisiting a project I haven't worked on for a while and the first time I've run the project in simulator I'm getting an error I can't work out.

I have a collection view and each cell links to a detailed view controller. This used to work fine but now when I click on a cell I get the following error

Attempt to present "Detailed view" on "Collection View" whose view is not in the window hierarchy!

How can the 'didSelectItemAtIndexPath' be firing to instigate the segue if the view is not in the window hierarchy? This is the code that is called and println statement is printed so I know the code is being read. I've also checked and the segue names are correct.

  func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    switch (indexPath.item) {
    case 0:
      performSegueWithIdentifier("showMonth", sender: self)
      println("cell pressed")
      break;

    case 1:
      performSegueWithIdentifier("showPromotions", sender: self)
      println("cell pressed")      
      break;

    case 2:
      performSegueWithIdentifier("showRank", sender: self)
      println("cell pressed")   
      break;

    default:
      break;
    }

  }

It always used to work fine which I why I'm confused.

Jake Adams
Jake Adams
1,608 Points

Can you share the code or a link to a public repository?

1 Answer