Created
July 25, 2011 19:24
-
-
Save Nitewriter/1104953 to your computer and use it in GitHub Desktop.
#iOS: Nib-less Tab Bar Controller setup
This file contains hidden or 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
//... | |
int main(int argc, char *argv[]) | |
{ | |
// Add App Delegate class name as forth argument in UIApplicationMain() | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
int retVal = UIApplicationMain(argc, argv, nil, @"TestAppDelegate"); | |
[pool release]; | |
return retVal; | |
} | |
//... |
This file contains hidden or 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
//... | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// Override point for customization after application launch. | |
// Create a new window and assign directly to provided iVar | |
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
// Set background for window if desired | |
[self.window setBackgroundColor:[UIColor whiteColor]]; | |
UITabBarController *tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil]; | |
NSMutableArray *controllers = [NSMutableArray arrayWithCapacity:0]; | |
for (int index = 0; index < 4; index ++) | |
{ | |
NSString *title = [NSString stringWithFormat:@"Controller %d", index]; | |
// Replace with custom controllers for all desired tabs | |
UIViewController *controller = [[UIViewController alloc] initWithNibName:nil bundle:nil]; | |
[controller setTitle:title]; | |
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller]; | |
[controller release]; | |
// Tag, title and apply images as desired | |
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title image:nil tag:index * 1000]; | |
[nav setTabBarItem:item]; | |
[item release]; | |
[controllers addObject:nav]; | |
[nav release]; | |
} | |
// Assign controller to tab bar controller | |
[tbc setViewControllers:controllers]; | |
// Set tab bar controller as root view controller | |
[self.window setRootViewController:tbc]; | |
[tbc release]; | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment