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 Build a Self-Destructing Message iPhone App Capturing Photo and Video Using UIImagePickerController Presenting the UIImagePickerController (Camera View)

Stanley Gao
Stanley Gao
3,889 Points

I received an error when presenting a modal view controller. It says my view controller is detached. Any solution?

Error message: "Presenting view controllers on detached view controllers is discouraged <CameraViewController: 0x7fd32a42e2b0>."

Base on my understanding, the message is telling me that my recipients view controller is detached from storyboard, hence it causing trouble when I tried to present a modal view controller above it.

However, I have went through my storyboard, and I have the navigation controller and initial tab bar view controller hooked up, so what is the problem here? What does it mean by view controller being detached? How can I fix this issue?

Thomas Skjelstad
Thomas Skjelstad
11,541 Points

If you present a view from a childviewcontroller it will give you that warning. to avoid this, you can present a view on childviewcontroller's parent.

[self.parentViewController presentViewController:viewController animated:YES completion:nil];

Stanley Gao
Stanley Gao
3,889 Points

Ok, I see what it means. In my app, I have a table view controller embedded in a navigation controller which is one of the scenes of a tab bar controller. If I want to add a modal view to this table view controller, where should I add the segue way? Which view controller is the parent? The navigation controller or The tab bar controller?

2 Answers

Thomas Skjelstad
Thomas Skjelstad
11,541 Points

You will be presenting the modalViewController over the TableViewController that shows your list of friends. It has been a while since i did this project. watch the video again, and pay attention to what he is doing. Make sure you put the code in the right viewController. and that the custom class is added to the storyboard. the modalViewController is presented programmaticly if i don't remember way off.

Stanley Gao
Stanley Gao
3,889 Points

I tried to present the modal view controller over the table view controller and the navigation controller. Both of them had the "detached view controller" warning. I reviewed his videos and I definitely put my code in the cameraViewController under viewWillAppear.

There is another detail I forgot to mention. After I tap on the camera tab, the app doesn't respond instantly, it freezes for a second. And before it brings up the camera you can see the tableView of the list of friends flashes for a very brief moment. In another word, the tableView shows prior to the modalView

Ryan Summe
Ryan Summe
4,618 Points

I have this same warning, no crash and it all works fine but a little concerning. Perhaps something Xcode 6 related? I also tried using self.parentViewController but the warning still persists.