Multiple Calls to viewWillAppear + viewDidAppear... iOS5.1

74 views
Skip to first unread message

Greg

unread,
Mar 11, 2012, 11:07:02 PM3/11/12
to myLauncher
Is anyone aware of an issue with iOS5.1 (possibly 5.0) and the
viewController logic of MyLauncher which results in multiple calls to
viewWillAppear and viewDidAppear etc?

This problem is of course causing issues with my code!

Here's log from most recent build of myLauncher on XCode 4.3.2 iOS5.1
simulator:
(open launcher item1 and close it)

2012-03-11 22:52:23.024 MyLauncher[7179:f803] MyLauncherViewController
- viewWillAppear
2012-03-11 22:52:23.074 MyLauncher[7179:f803] MyLauncherViewController
- viewDidAppear
2012-03-11 22:52:24.192 MyLauncher[7179:f803] ItemViewController -
viewWillAppear
2012-03-11 22:52:24.195 MyLauncher[7179:f803] ItemViewController -
viewWillAppear
2012-03-11 22:52:24.197 MyLauncher[7179:f803] ItemViewController -
viewDidAppear
2012-03-11 22:52:24.199 MyLauncher[7179:f803] ItemViewController -
viewDidAppear
2012-03-11 22:52:24.201 MyLauncher[7179:f803] ItemViewController -
viewDidDisappear
2012-03-11 22:52:24.202 MyLauncher[7179:f803] ItemViewController -
viewDidAppear
2012-03-11 22:52:33.326 MyLauncher[7179:f803] ItemViewController -
viewWillDisappear
2012-03-11 22:52:33.327 MyLauncher[7179:f803] ItemViewController -
viewWillDisappear
2012-03-11 22:52:33.328 MyLauncher[7179:f803] ItemViewController -
viewDidDisappear
2012-03-11 22:52:33.328 MyLauncher[7179:f803] MyLauncherViewController
- viewWillAppear
2012-03-11 22:52:33.329 MyLauncher[7179:f803] MyLauncherViewController
- viewDidAppear
2012-03-11 22:52:33.330 MyLauncher[7179:f803] ItemViewController -
viewDidDisappear

I found the following question on StackOverFlow:
http://stackoverflow.com/questions/7830830/ios-different-addsubview-behavior-between-ios-4-3-and-5-0

I think we need to update MyLauncher to account for this change in the
way viewWill & Did appear with ChildViewControllers in iOS5 vs. iOS4!

Thanks!

Jim Malak

unread,
Mar 12, 2012, 12:34:50 PM3/12/12
to mylau...@googlegroups.com
Hi Greg,

I have a version up and running under iOS 5.1 that seems to be fine. I
only see the two methods getting called once. Did you want to try this
version? Let me know and I will send it to you

Thanks,
Jim Malak

Gregory P. Moore, MD

unread,
Mar 12, 2012, 1:19:00 PM3/12/12
to mylau...@googlegroups.com
Jim -- thanks a bunch for your offer.  Do you have it on GitHub as a  branch?  

Let me know if you have something different, but here's what I did last night (which seems to work even though I hate hacks like this):

- (void)closeView {
UIView *viewToClose = [[self.launcherNavigationController topViewController] view];
viewToClose.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.3 
  delay:0 
options:UIViewAnimationOptionCurveLinear 
animations:^{
viewToClose.alpha = 0;
viewToClose.transform = CGAffineTransformMakeScale(0.00001, 0.00001);
self.overlayView.alpha = 0;
}
completion:^(BOOL finished){
                         if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
                             [[self.launcherNavigationController topViewController] viewWillDisappear:NO];
                         }
                         [[self.launcherNavigationController view] removeFromSuperview];
                         if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
                             [[self.launcherNavigationController topViewController] viewDidDisappear:NO];
                         }
                         [self.launcherNavigationController setDelegate:nil];
                         [self setLauncherNavigationController:nil];
                         [self setCurrentViewController:nil];
[self.parentViewController viewWillAppear:NO];
[self.parentViewController viewDidAppear:NO];
}];
}





#pragma mark - UINavigationControllerDelegate

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
        if (self.currentViewController) {
            [self.currentViewController viewWillDisappear:animated];
        }
        [viewController viewWillAppear:animated];
    }
}

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
        if (self.currentViewController) {
            [self.currentViewController viewDidDisappear:animated];
        }
        [viewController viewDidAppear:animated];
        [self setCurrentViewController:viewController];
Reply all
Reply to author
Forward
0 new messages