Created
April 8, 2013 08:24
-
-
Save HHuckebein/5335161 to your computer and use it in GitHub Desktop.
Initialize the sequence of UITabBarControllers read for userdefaults
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
// | |
// | |
// | |
// | |
// Created by Bernd Rabe on 07.08.12. | |
// Copyright (c) 2012 RABE_IT Services. All rights reserved. | |
// | |
#pragma mark - TabBarController Sequence | |
// load an array from the user defaults database | |
// if the array exists it sorts the tabBar view controller accordingly | |
// if not, it just fills the tabBarControllerSequence array | |
// with the default tag values of the view controllers sequence | |
// defined in the MainWindow.nib file | |
// tabBarItem tags must be set in MainWindow.nib and | |
// should start with 0 | |
- (void)initTabBarVCSequenceAndSelectionWithUserDefaults | |
{ | |
NSMutableArray *tmp = [[NSMutableArray alloc] initWithArray:self.tabBarControllerSequence copyItems:YES]; | |
NSMutableArray *viewControllers = [NSMutableArray array]; | |
NSUInteger count = [tmp count]; | |
NSArray *vcArray = [self.appDelegate.tabBarController viewControllers]; | |
NSInteger index = 0; | |
for (NSUInteger i = 0; i < count; i++) | |
{ | |
NSInteger viewControllerTag = [[tmp objectAtIndex:i] integerValue]; | |
// reorder the view controllers according tabBarControllerSequence | |
if (i != count - 1) { | |
[vcArray indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { | |
*stop = [[obj tabBarItem] tag] == viewControllerTag; | |
if (*stop) { | |
[viewControllers addObject:obj]; | |
} | |
return *stop; | |
}]; | |
} | |
else { | |
if (viewControllerTag == NSNotFound) { | |
// identifies the more navigation controller | |
self.appDelegate.tabBarController.selectedViewController = [self.appDelegate.tabBarController moreNavigationController]; | |
} | |
else { | |
index = [viewControllers indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { | |
*stop = [[obj tabBarItem] tag] == viewControllerTag; | |
return *stop; | |
}]; | |
} | |
} | |
} | |
[self.appDelegate.tabBarController setViewControllers:viewControllers animated:NO]; | |
self.appDelegate.tabBarController.selectedViewController = [viewControllers objectAtIndex:index]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment