From 7e538f20e35d16d4749e0b31304afdd5fc334567 Mon Sep 17 00:00:00 2001 From: Robert Dimitrov Date: Thu, 11 Dec 2014 18:34:13 +0200 Subject: [PATCH] Fix a bug where old view controllers and tab bar items were not removed properly when setting new ones. --- RDVTabBarController/RDVTabBar.m | 4 ++-- RDVTabBarController/RDVTabBarController.m | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/RDVTabBarController/RDVTabBar.m b/RDVTabBarController/RDVTabBar.m index 8da27e4..03aada1 100755 --- a/RDVTabBarController/RDVTabBar.m +++ b/RDVTabBarController/RDVTabBar.m @@ -99,12 +99,12 @@ - (void)setItemWidth:(CGFloat)itemWidth { } - (void)setItems:(NSArray *)items { - for (RDVTabBarItem *item in items) { + for (RDVTabBarItem *item in _items) { [item removeFromSuperview]; } _items = [items copy]; - for (RDVTabBarItem *item in items) { + for (RDVTabBarItem *item in _items) { [item addTarget:self action:@selector(tabBarItemWasSelected:) forControlEvents:UIControlEventTouchDown]; [self addSubview:item]; } diff --git a/RDVTabBarController/RDVTabBarController.m b/RDVTabBarController/RDVTabBarController.m index a737f80..7eee511 100755 --- a/RDVTabBarController/RDVTabBarController.m +++ b/RDVTabBarController/RDVTabBarController.m @@ -123,6 +123,14 @@ - (void)setSelectedIndex:(NSUInteger)selectedIndex { } - (void)setViewControllers:(NSArray *)viewControllers { + if (_viewControllers && _viewControllers.count) { + for (UIViewController *viewController in _viewControllers) { + [viewController willMoveToParentViewController:nil]; + [viewController.view removeFromSuperview]; + [viewController removeFromParentViewController]; + } + } + if (viewControllers && [viewControllers isKindOfClass:[NSArray class]]) { _viewControllers = [viewControllers copy];