Created
November 13, 2012 05:04
-
-
Save hborders/4064006 to your computer and use it in GitHub Desktop.
Example of my use of UIViewController containment lifecycle methods inside a custom tab bar controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) setSelectedViewController:(UIViewController<SFCustomTabbedViewController> *)selectedViewController { | |
if (_selectedViewController != selectedViewController) { | |
if (_selectedViewController) { | |
NSUInteger selectedViewControllerIndex = [self.viewControllers indexOfObject:_selectedViewController]; | |
if (selectedViewControllerIndex != NSNotFound) { | |
UIButton *tabButton = [self.tabButtons objectAtIndex:selectedViewControllerIndex]; | |
tabButton.selected = NO; | |
} | |
[_selectedViewController willMoveToParentViewController:nil]; | |
[_selectedViewController.view removeFromSuperview]; | |
[_selectedViewController removeFromParentViewController]; | |
} | |
_selectedViewController = selectedViewController; | |
if (_selectedViewController) { | |
[self view]; // guarantee loadView gets called | |
[self addChildViewController:_selectedViewController]; | |
_selectedViewController.view.autoresizingMask = | |
UIViewAutoresizingFlexibleWidth | | |
UIViewAutoresizingFlexibleHeight; | |
_selectedViewController.view.frame = self.selectedViewControllerContainerView.bounds; | |
[self.selectedViewControllerContainerView addSubview:_selectedViewController.view]; | |
[_selectedViewController didMoveToParentViewController:self]; | |
NSUInteger selectedViewControllerIndex = [self.viewControllers indexOfObject:_selectedViewController]; | |
if (selectedViewControllerIndex != NSNotFound) { | |
UIButton *tabButton = [self.tabButtons objectAtIndex:selectedViewControllerIndex]; | |
tabButton.selected = YES; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment