briancollins / BCTabBarController

a Tweetie-style tab bar for the iPhone
MIT License
568 stars 95 forks source link

ViewWillAppear and other methods not called #13

Closed batkov closed 8 years ago

batkov commented 12 years ago

ViewWillAppear, ViewDidAppear, ViewWillDisappear ViewDidDisappear methods not called in selectded view controller and not called into BCTabBarController. This problem appears after BCTabBarController show modal controller from instance of BCTabBarController class.

batkov commented 12 years ago

Feature presented on iOS 4.3, but not on iOS 5

vvit commented 12 years ago

I have the same problem. Since I need a call of viewDidAppear I added notification into the end of - tabBar:didSelectTabAtIndex: (BCTabBarController.m)

if ([[[UIDevice currentDevice] systemVersion] compare:@"5.0" options:NSNumericSearch] == NSOrderedAscending)
{
        [[NSNotificationCenter defaultCenter] postNotificationName:kTabChangedNotification object:self userInfo:
                                [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:index] forKey:@"index"]];
}
morgz commented 12 years ago

in BCTabBarController I think we need this.. fixes it for me when I'm using navigationControllers

- (void)setSelectedViewController:(UIViewController *)vc {
        UIViewController *oldVC = selectedViewController;
    if (selectedViewController != vc) {
        selectedViewController = vc;
        if (!self.childViewControllers && visible) {
            [oldVC viewWillDisappear:NO];
            [selectedViewController viewWillAppear:NO];

            if ([selectedViewController isMemberOfClass:[UINavigationController class]]) {
                UINavigationController *navController = (UINavigationController *)selectedViewController;
                [navController.topViewController viewWillAppear:NO];
            }
        }
        self.tabBarView.contentView = vc.view;
    if (!self.childViewControllers && visible) {
        [oldVC viewDidDisappear:NO];
        [selectedViewController viewDidAppear:NO];

        if ([selectedViewController isMemberOfClass:[UINavigationController class]]) {
            UINavigationController *navController = (UINavigationController *)selectedViewController;
            [navController.topViewController viewDidAppear:NO];
        }
    }

    [self.tabBar setSelectedTab:[self.tabBar.tabs objectAtIndex:self.selectedIndex] animated:(oldVC != nil)];
}
}