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 trialPerry Rose
413 PointsCamera keeps opening when code is placed in (void)viewWillAppear
When I put my code to access the camera/photo album inside - (void)viewWillAppear:(BOOL)animated, the camera/photo album keeps opening after every time I take/select a photo.
When I put the same code back under - (void)viewDidLoad, everything works fine, and doesn't keep opening. But the code can't be inside 'viewDidLoad' as I won't be able to access the camera/photo album twice.
Is anyone else having problems with this?
I have watched the tutorials 4 times now and I know my code is correct. Could this be because I am using a newer version of Xcode?
Cheers, Perry.
1 Answer
Martin Wildfeuer
Courses Plus Student 11,071 PointsI have not checked the assignment, but this is intended behavior.
- (void)viewWillAppear:(BOOL)animated
will be called everytime your view will appear, that is becomes visible as the topmost view controller. When you open the camera, your viewWillDisappear
as the camera is added as the topmost view controller. As soon as your done, the camera is removed from the hierarchy and your view controller becomes visible again, thus triggering viewWillAppear
.
All code that is intended to only be executed once should not go into viewWillAppear
. You can read more on the view lifecycle here.