Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-07-2009, 08:35 PM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 24
Default Nesting UITabBar into UINavigation Controller

Hiya, I would like to know if there's an example of this anywhere. Basically I would like to push the UITabBar, and keeping with apple's guidelines I can only do this by placing the UITabBar(not the controller) in a viewController. Examples of this are in the Music selection on your iPhone/iTouch when you hit the "Now Playing" nav item, notice the tab bar pushes over.

This is somewhat of the flow I'm trying to accomplish


Code:
                                                  -----> Table (cell 1)----> Detail View 
                                                 |
Navigation Controller ----> UITabBar-|----------> view 2
                                                 |
                                                  -----> view 3
So when the app launches I'm greeted with my tab bar and when I select a cell from the tableView the detail view is pushed onto the stack resulting in a possible customized button bar at the bottom of that view.

Another good example of this functionality is the NYTimes app (it's free if you want to check it out)

Now I got the basics of this running, but I'm getting crashes when trying to wire IBOutlets to the tab items in IB. Would appreciate some insight on this.

Thx much!

Last edited by lildragon; 07-07-2009 at 08:44 PM.
lildragon is offline   Reply With Quote
Old 07-07-2009, 10:11 PM   #2 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 24
Default

Well I've dabbled a little more since posting, everything succeeds but still crashes on load.. Here's the code I have so far

AppDelegate.h

Code:
#import <UIKit/UIKit.h>
 
@interface AppDelegate : NSObject <UIApplicationDelegate> 
{
    UIWindow *window;
    UINavigationController *navigationController;
}
 
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 
 
@end


AppDelegate.m

Code:
#import "AppDelegate.h"
 
@implementation AppDelegate
 
@synthesize window;
@synthesize navigationController;
 
- (void)applicationDidFinishLaunching:(UIApplication *)application 
{    
    // Override point for customization after application launch
	// Configure and show the window
	[window addSubview:[navigationController view]];
	[window makeKeyAndVisible];
}
 
- (void)applicationWillTerminate:(UIApplication *)application 
{
	// Save data if appropriate
}	
 
- (void)dealloc {
	[navigationController release];	
    [window release];
    [super dealloc];
}
 
 
@end


TabViewController.h

Code:
#import <UIKit/UIKit.h>
 
 
@interface TabViewController : UIViewController <UITabBarDelegate> 
{
        IBOutlet UITabBar *tabBar;
	IBOutlet UITabBarItem *featuresTabBarItem;
	UIViewController *selectedViewController; 
}
 
@property (nonatomic, retain) IBOutlet UITabBar *tabBar;
@property (nonatomic, retain) IBOutlet UITabBarItem *featuresTabBarItem;
@property (nonatomic, retain) UIViewController *selectedViewController;
 
@end


TabViewController.m

Code:
#import "TabViewController.h"
#import "FeaturesTabViewController.h"
 
 
@implementation TabViewController
 
@synthesize selectedViewController;
@synthesize tabBar;
@synthesize featuresTabBarItem;
 
 
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
		
        // Custom initialization
		FeaturesTabViewController *featuresTabViewController = [[FeaturesTabViewController alloc] initWithNibName:@"FeaturesTabView" bundle:nil];
    
		[self.view addSubview:FeaturesTabViewController.view];
	        self.selectedViewController = featuresTabViewController;	
 
		[featuresTabViewController release];		
	
	}
    return self;
}
 
 
 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{
	tabBar.selectedItem = featuresTabBarItem; 
	[super viewDidLoad];
}
 
 
- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}
 
- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}
 
 
- (void)dealloc 
{
	[tabBar release];
	[featuresTabBarItem release];
	[selectedViewController release];	
    [super dealloc];
}
 
 
@end
I would appreciate any insight! thx
lildragon is offline   Reply With Quote
Old 07-07-2009, 10:11 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 152
Default

I highly recommend doing it the opposite way. You should have the tab bar controller as the root and then launch navigation controllers when the various tabs are selected. This is almost always how it is implemented.

Check out this tutorial, it is pretty clear and a good guideline.

YouTube - Building an iPhone App Combining Tab Bar, Navigation and Tab
JCooperman is offline   Reply With Quote
Old 07-07-2009, 10:20 PM   #4 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 24
Default

Quote:
Originally Posted by JCooperman View Post
I highly recommend doing it the opposite way. You should have the tab bar controller as the root and then launch navigation controllers when the various tabs are selected. This is almost always how it is implemented.

Check out this tutorial, it is pretty clear and a good guideline.

YouTube - Building an iPhone App Combining Tab Bar, Navigation and Tab
Yup this is the way I did it before, but I ran into the issue where the tabBarController can't be pushed since the NavigationController is a subclass of Tab. I do have to admit, this way is annoying but I can't think of another way to achieve the navigation flows I mentioned in the OP. But yeah that's a nice link!

~t
lildragon is offline   Reply With Quote
Old 07-08-2009, 12:41 PM   #5 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 78
Default

Greetings!

Regarding the NYTimes app, it's a bit of an illusion in play there. They _do_ keep the tab bar at the top level, with all the various navigation controllers under its watch.

Now, it's true that, when you pick one of the articles, the tab bar is pushed aside. You'd think that means the tab bar was in a view managed by a navigation controller. Not so! It's a lot easier than that.

Keep the tab/nav bar hierarchy as you've seen in other examples, but - when it comes time to push your detail view into place, and you want that tab bar pushed aside temporarily, set the hidesBottomBarWhenPushed property to YES in your detail's view controller, and do that before pushing the VC onto your nav bar controller's stack. That should do it!

Also see the iPhoneCoreDataRecipes sample app from Apple Dev Network. I believe that makes use of this property as well.

Let me know if that helps!
jdandrea is offline   Reply With Quote
Old 07-08-2009, 09:07 PM   #6 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 24
Default

jdandrea as I said in the other thread thank you! With one line of code I don't have to bust my brain with the above workaround... that's a serious load off

Cheers!
lildragon is offline   Reply With Quote
Old 07-09-2009, 06:03 AM   #7 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 78
Default

Quote:
Originally Posted by lildragon View Post
jdandrea as I said in the other thread thank you! With one line of code I don't have to bust my brain with the above workaround... that's a serious load off

Cheers!
You're welcome! I'm very glad to hear you won't have to go with that workaround either.
jdandrea is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,203
Threads: 38,982
Posts: 171,002
Top Poster: smasher (2,568)
Welcome to our newest member, sfeast
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:24 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0