Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 10-16-2009, 06:20 AM   #306 (permalink)
ujagtap
Umesh Jagtap
 
ujagtap's Avatar
 
Join Date: Sep 2009
Location: Pune, India
Posts: 35
ujagtap is on a distinguished road
Default

Quote:
Originally Posted by DevTeamOfOne View Post
Code:
@interface AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
    MyTableViewController *myTableViewController;
    MySecondTableViewController *mySecondTableViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@property (nonatomic, retain) MyTableViewController *myTableViewController;
@property (nonatomic, retain) MySecondTableViewController *mySecondTableViewController;

@end




@implementation AppDelegate

@synthesize window, myTableViewController, mySecondTableViewController, tabBarController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

       tabBarController = [[UITabBarController alloc] init];          // creates your tab bar so you can add everything else to it

       myTableViewController = [[MyTableViewController alloc] init];               // creates your table view - this should be a UIViewController with a table view in it, or UITableViewController
       UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:myTableViewController] autorelease];
       [myTableViewController release];                                                              // creates your table view's navigation controller, then adds the view controller you made. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.

       mySecondTableViewController = [[MySecondTableViewController alloc] init];   
       UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:mySecondTableViewController] autorelease];
       [mySecondTableViewController release];                                                    // does exactly the same as the first round, but for your second tab at the bottom of the bar.

       tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; add both of your navigation controllers to the tab bar. You can put as many controllers on as you like, but they will turn into the more button like in the iPod program.

       [window addSubview:tabBarController.view];                                              // adds the tab bar's view property to the window
       [window makeKeyAndVisible];                                                                  // makes the window visible
}

- (void)dealloc {
       [tabBarController release];
       [window release];
       [super dealloc];
}                                           // lets go of everything else, thats so your program doesn't create any leaks of memory.

@end

I just typed up this quick App Delegate to show you how to do it. Yes, you do have rights to use whatever part of it you wish, and yes, you can ask any questions you like.

Please do note:
a ) I release the table views because they have been retained by the Navigation Controllers. Thus, I have doubled up and am taking double the memory. Once you have a nav controller holding your view, drop it. This saves memory. These nav controllers are set to drop automattically with their autorelease so there is no leak issue.

b ) if you need to add only one item to your tabBar for some strange reason, or just to test, change "arrayWithObjects: blah, blah2, nil" to "arrayWithObject: blah" and drop the nil.

Does this help you???
Hi DevTeamOfOne,

I am new to iPhone development. This thread really help me to create tabBarController and NavigationController in it. Is it possible to change tabBarController's color to Default color. Please help.

Thanks in advance!!
ujagtap is offline   Reply With Quote
 

» Advertisements
» Online Users: 933
22 members and 911 guests
ADY, anil_shanebond, AReality, avocet, brush51, Cnmcc, DaveDee, dcool, equalsabracket, fouldsc, Gary OBrien, greeneye82, Insider, Kobold, matador1978, MrDrewC, myach, nanoDeveloper, nestochi, nobre84, shwetap, woriykh
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,284
Threads: 93,960
Posts: 402,311
Top Poster: BrianSlick (7,971)
Welcome to our newest member, shwetap
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:58 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.