 |
 |
|
 |
07-07-2009, 08:35 PM
|
#1 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 24
|
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.
|
|
|
07-07-2009, 10:11 PM
|
#2 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 24
|
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
|
|
|
07-07-2009, 10:11 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 152
|
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
|
|
|
07-07-2009, 10:20 PM
|
#4 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 24
|
Quote:
Originally Posted by JCooperman
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
|
|
|
07-08-2009, 12:41 PM
|
#5 (permalink)
|
|
Registered Member
Join Date: May 2009
Posts: 78
|
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!
|
|
|
07-08-2009, 09:07 PM
|
#6 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 24
|
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!
|
|
|
07-09-2009, 06:03 AM
|
#7 (permalink)
|
|
Registered Member
Join Date: May 2009
Posts: 78
|
Quote:
Originally Posted by lildragon
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.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 391 |
| 52 members and 339 guests |
| BolderImage, ChrisMayer, damienbern, DanLyons, dave1619, daxappvi, Don, Dorald, dre, ershaer, Exaviorn, firearasi, Forsworn, frankenspank, funhog, gonk, gshaviv, harrytheshark, hatembr, headkaze, hm50, iGeorG, imhotep85, Janek2004, JonnyBGoode, jyu, Kalimba, kiksy, KinAz, listingboat, Locker, MadMark, masc2279, moehac, Mopedhead, mpramodjain, Mr Jack, nobre84, Noise, PhotoShootoutApp, refreshe, Rudy, rybek, SalvoMaltese, sayer, sfeast, SimonHodgkiss, stifmaister, TunaNugget, upperhouse, wilky94, zulfishah |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,203
Threads: 38,982
Posts: 171,002
Top Poster: smasher (2,568)
|
| Welcome to our newest member, sfeast |
|