Skip to content

Commit

Permalink
Fix a bug where old view controllers and tab bar items were not remov…
Browse files Browse the repository at this point in the history
…ed properly when setting new ones.
  • Loading branch information
robbdimitrov committed Dec 11, 2014
1 parent 145246a commit 7e538f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions RDVTabBarController/RDVTabBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
8 changes: 8 additions & 0 deletions RDVTabBarController/RDVTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 7e538f2

Please sign in to comment.