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 trialAlbert Mon
277 PointsPhotoBomber[3396:53988] Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x79a868c0>.
I receive this log message when I run the application. I believe it is because of instagram login view being called in the UIColloectionViewController. It does not make the application crash. However, I would like to know if there is any enhancement to solve this issue.
7 Answers
Evan David
4,296 PointsI was experiencing the same issue, which was a strange side effect of having no network connectivity in the simulator. I reset the content and settings on the simulator which at least temporarily 'resolved' the issue.
Chris McKnight
11,045 PointsThis can happen for a few different reasons. Most of the time it is because you are animating 2 things at the same time. I have seen this happen when calling popToViewControllerAnimated:
twice with both calls passing in YES
. Another time this will occur is when you try to present a view controller from the view controller.
Albert Mon
277 PointsThanks Chris, I believe my problem is related with presenting a view controller from the view controller. Is there any way to solve this problem?
Chris McKnight
11,045 PointsYes, can you post some relevant code?
Marcus Marshall
5,520 PointsChris! I'm having the same problem with my code. Is there any thing you could do to help me?
'''ObjectiveC
-(void)viewDidLoad { [super viewDidLoad];
self.title = @"#PhotoBomb";
[self.collectionView registerClass:[THPhotoCell class] forCellWithReuseIdentifier:@"photo"];
self.collectionView.backgroundColor = [UIColor whiteColor];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
self.accessToken = [userDefaults objectForKey:@"accessToken"];
if (self.accessToken == nil) {
[SimpleAuth authorize:@"instagram" completion:^(NSDictionary *responseObject, NSError *error) {
NSString *accessToken = responseObject[@"credintials"][@"token"];
[userDefaults setObject:accessToken forKey:@"accessToken"];
[userDefaults synchronize];
}];
} else {
NSURLSession *session = [NSURLSession sharedSession];
NSString *urlString = [[NSString alloc] initWithFormat:@"https://api.instagram.com/v1/tags/photobomb/media/recent?access_token=%@",self.accessToken];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSString *text = [[NSString alloc]initWithContentsOfURL:location encoding:NSUTF8StringEncoding error:nil];
NSLog(@"text: %@", text);
}];
[task resume];
}
}
'''
Chris McKnight
11,045 PointsMove your code into viewDidAppear
and the warning should go away. The problem with viewDidLoad
is that the UINavigationController
hasn't finished its animation yet. So, the navigation controller's animation is still happening when the modal's animation happens.
Marcus Marshall
5,520 PointsMoving the code to viewDidAppear puts the modal view animation into a continuous loop. The simulator presents the modal view and then dismisses it over and over.
Chris McKnight
11,045 PointsYou're absolutely right. viewWillAppear
and viewDidAppear
are going to fire every time the modal opens and closes. It seems like the following are the only solutions:
- Disable the animation on the modal
- Wait until the navigation controller has finished its animation
- Move the code into a new method and call the method after a delay
Marcus Marshall
5,520 PointsWhich do you think would be the best implement in this scenario and how would you do so? I'm only half a year into coding so I'm pretty new to this. Thank you so much for all your help!
Chris McKnight
11,045 PointsI think the best is to show the modal after the animation has finished otherwise the UI might change abruptly.
James Lin
4,601 PointsI have a hacky solution to resolve this issue:
set a global: BOOL firstLoad;
in viewDidLoad: firstLoad = YES;
move the entire oAuth code to viewDidAppear and put int a if(firstLoad) { //oauth code}. after it is complete set firstLoad = NO;
This will ensure that the it executes when the navigation controller has finished animating, but only executes the oAuth stuff once