[iPhone] Nesting a UINavigationController in a UITabBar

Some background on my problem:
I looked through the sample code for SimpleDrillDown, which is basically a tutorial for using the Nav controller with UITableViews. So I made my own project, and basically redid what was in the sample. This works fine for me. Basically I have the app delegate, a RootViewController, and a DetailViewController (which acts as the inspector).
In the AppDelegate's applicationDidFinishLaunching: method, it does some basic setup. Creates the RootViewController and adds it to the AddDelegate's ivar of UINavigationController. It then sets the window's subview to be the view of navController. That's basically what the sample does, and same with my own.
Now I'm trying to add a tab bar to my application. I've read the View Controller programming guide, which was pretty straightforward. There is a section for adding NavControllers to a UITabBarController. The instructions read like I expected them too, and seem logical. But I'm having trouble...
So what I did was this.. left my code the way it was, and added a UITabBarController to my AppDelegate. In the applicationDidFinishLaunching: method, I initialized the tabBarController. In the View Controller Programming guide, it then says to set tabBarController.views property to an NSArray of view controllers (one for each tab of the tabBar). Makes sense. So I made an array containing only the navBarController I previously made. I then set this array to the tabBarController.views property. Then I added the tabBarController.view as the window's subview (instead of the navController's view as before).
When I run the application, I get a tabBar visible, but it's completely white, and there is only one, blank tabBarItem in the bar at the bottom. I inspected my code with GDB after I set the tabBarController.view property, and it appears it does not set, as the value in the debugger is 0x0.. The rest of the tabBarController has proper values, but the views array doesn't seem to want to set.
So this is kind of driving me crazy. I hope my explanation made sense (and also wasn't too verbose...heh). If anyone has any ideas please let me know, this is really bugging me!
Thanks again,
JB.

OK. I will try this when I get home, it sounds reasonable.
I've been looking around more and it appears there is an error in the View Controller Programming guide, in the line where I initialize the tabBarController.
In the docs it says something like:
UITabController *tabController = [[UITabController alloc] initWithNibName:nil bundleName:nil];
The solutions I've read sugguest this is an error and instead should just be:
UITabController *tabController = [[UITabController alloc] init];
Again, I will try this out as well when I get home, and report back.
Thanks!

Similar Messages

  • IPhone: Turning off UINavigationController back animation...

    I am pushing some views into the nav controller stack with animation turned off. But the back button still performs the animation. Is there a way to turn that off using the default back button, or do I need to roll-my-own in this case and perform the pops in code.

    Hi, I need to do the same thing. Did you ever find a good way to do this?

  • How get changed view based on selected tabBarItem

    Hi All,
    i have used UINavigationController and used UITabBar from IB.
    I have added 3 UITabBarItem named 1. search 2. Recents and 3 .Favorites.
    Now when i clicked on search item it should be open serachViewController and same as remaining two items,
    But i can;t understand that how can i get that which items are selected ....
    pls help me again....buddy
    Thanks.

    I think this is what you are asking for-
    In IB, click on each tab bar button and set the NIB name of the tab controller buttons to the NIB name of your other views, and set the Class of the of each button to the Class files that control those views. Then clicking on each button will load separate NIB files.
    Also, working in tree-view in IB makes it easier to understand what's connected to what when working with controllers like Navigation and TabBar.
    Hope that helps-

  • NSDecimalNumber returns positive number for "-10.045".

    Hello,
    I am developing iPhone application with UINavigationController. Today I noted that negative values stopped converted to negative numbers. Instead I started getting positive values.
    I narrowed the issue down and I finally I get the code that shows the error:
    NSLog(@"check negative %@ %@ ", @"-10.045", [NSDecimalNumber decimalNumberWithString:@"-10.045"]);
    I dump that twice: when the app starts and when I click any button.
    The output is following:
    check negative -10.045 -10.045
    check negative -10.045 10.045    
    So the first call returns correct value, the second one was not. That looks very very strange.
    My environment: MacOS 10.6.7, Xcode 4.2 build 4C199, target iPhone 5.0 simulator.
    I did not tested on read device, but when I changed target to iPhone 4.0 simulator, the issue was done.
    Any ideas?
    Regards,
    Valery.

    When we call the method getTypeinfo on DatabaseMetaData to see the supported dataType, it returns data Type 4 for number which is defined in java.sql.Types. But why it returns 3 which is defined as constant for decimal in java.sql.Types

  • [iPhone] UITabBar, UINavigationController, etc.

    I am very new to iPhone and Cocoa/Obj-C, but have been working in the .NET world for quite some time building WM apps using the .NET Compact Framework.
    Let's say I have an application design that uses a tab view with 3 tabs as its main UI metaphor. In the first 2 tabs, I want to have navigation controllers, and in the last tab I want to have just a simple view.
    The first tab is the hardest, since I need the navigation controller to be able to switch out its top-level view between a table view and a graphical representation of the data in the table. This might be a UIWebView, but I don't know that yet. Interacting with either of these top-level views should push onto the navigation controller's stack a new view with some detail information about the list item selected. In the top level view, I need the navigation bar to display a left "refresh" button, a center "segment controller" with 2 segments, and a right "edit" button. The center segment controller will be used to toggle between the base table view and the graphical view. Is there a way to just swap the top level views of a navigation controller? When an item is selected and the detail view is pushed onto the stack, the navigation bar of the detail view needs to change to provide the typical "Back" button and possibly some other right button (to be determined). Is this even possible? Does it have to be done in code, or can I use IB to do it?
    The second tab is a relatively simple table->detail navigation scheme. I might add some functionality to it later, but for now that's all I need.
    I guess my biggest question would be: what are some best practices for getting this done? I think I would prefer to use IB, as this allows me to better see the UI I am crafting, but I am not "married" to it, per se.
    As to hooking into the tab bar, I would like to be able to decompose the problem into the various views that will be used for each tab, and then add those views to the tab bar. In the IB examples I've seen (including the UITabBar template project in XCode), the tab bar is configured to have tabs that "are" navigation controllers, and the navigation bar is laid out directly within the tab bar view. Is that really a "best practice," or is it more correct to set each tab's view to be a separately crafted class that may or may not be a UINavigationController or UITableViewController UIViewController or whatever?
    Thanks for whatever assistance you can offer,
    Matthew

    We bought two white 3G iPhones on launch night.
    Neither of them has exhibited any cracks, dust, or dead pixels yet (knock on wood). In terms of construction, they are good, except I don't really like the SIM card insert-it doesn't look well aligned compared to the almost seamless aluminum insert of the first gen iPhone.
    I've heard of the cracking issue (never seen it), but never the dust under screen one or leaking backlight one.
    My first gen iPhone has one dead pixel now, after over a year. (its amazing how on even a small screen that can get annoying) That would be one issue I would check first.
    For all the hassles of getting your phone activated in store (compared to last time), the one advantage is, if you have the time, you can completely examine your phone before you leave, with a Genius standing right there.
    Good luck!

  • UITabBar/UINavigationController issues with IB

    I'm unable to get nibs with UITabBar and a UINavigationController to work. Not sure if I'm doing this right since there's no docs, but here are the steps to reproduce:
    1. Drag a UITabBarController into the nib window
    2. Drag a UINavigationController into the nib window
    3. Make a connetion from the TabBarController's viewControllers outlet to the NavigationController
    4. Load the nib in you iPhone application
    I get the following exception when loading the nib:
    NSInvalidArgumentException, * -[NSCFArray insertObject:atIndex:]: attempt to insert nil
    I've tried many different combinations of setting this up, but I always get this same exception.
    Has anyone been able to setup a UITabBar with NavigationControllers in it? How did you do it?
    thanks,
    -=Scott

    Perhaps you already found a solution to issue... but in case you havent...
    The beta IB seems to be quirky so I am doing most of my view configuration manually.
    In lieu of IB based implementation here is a code snippet to create the UITabBarController and UINavigationController combination...
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Create a window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Create TabBar view controller and associated view controllers for the its TabBarItems.
    tabBarController = [[UITabBarController alloc] init];
    CustomViewController1 *viewController1 = [[CustomViewController1 alloc] init];
    UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController: viewController1];
    [viewController1 release];
    CustomViewController2 * viewController2 = [[CustomViewController2 alloc] init];
    UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController: viewController2];
    [viewController2 release];
    tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, navController2, nil];
    [navController1 release];
    [navController2 release];
    [window addSubview:tabBarController.view];
    // Display the window
    [window makeKeyAndVisible];
    The above code will create separate navigation bars for each of the tab bar "modes".
    Enjoy

  • 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
    -----> 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!

    Well I've dabbled a little more since posting, so the error is different. It's inconsistent tho, since sometimes it just quits on startup. Here's what I have so far
    AppDelegate.h
    #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
    #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
    #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
    #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
    And the FeaturesTabView .h/.m are generic
    Thx for any help!
    Message was edited by: lildragn

  • [IPhone] UITabBar and UIActionSheet

    Hi,
    I try to display UIActionSheet when I touch an item of UITabBar.
    I configure my UITabBar in appDelegate and I set appDelegate as UITabBarDelegate.
    Now when i touch an item of my UITabBar I could display an UIActionSheet if I want, but associated view controlle show immediately.
    So i search a solution to display the view controller I want after I touc an item of my UIActionSheet.
    An other problem is that when I write :
    myTabBar.selectedIndex = prevIndex;
    [myActionSheetDisplay showInview:myView];
    and in my method that catch event touch an action sheet button I write :
    if (buttonIndex == OK_BUTTON)
    myTabBar.selectedIndex = MYVIEWCONTROLLER;
    The view controller doesn't change and if I change the last line like this :
    myTabBar.selectedIndex = MYVIEWCONTROLLER-1;
    or anything else except the value of item I touch initially
    I'm waiting for an answer, thanks in advance

    UIActionSheet *actionSheet;
    actionSheet = [[UIActionSheet alloc]
    initWithTitle:@"Title"
    delegate:self
    cancelButtonTitle:@"Cancel"
    destructiveButtonTitle:nil
    otherButtonTitles:@"Bouton 1",@"Bouton 2", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    [actionSheet showInView:self.view];
    [actionSheet release];

  • [IPhone] UITabBar and autorotate

    Hi,
    I try to develop an application whith UITabBar, but I have some UIViewController with rotation enable.
    When I rotate simulator in landscape the autorotate method isn't invoke but is invoke when I rotate in portrait.
    I don't understand why because I try those UIViewController in application based on navigation controller and they work perfectly.
    I wait for yours answers.

    By default, Xcode gives you this function for view controller subclasses:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    Based on that, it will only rotate to portrait. To change that, you can either return YES which will allow rotation to every orientation, or check for the specific orientations you want.

  • RunTime Error on iPhone for UINavigationController

    I have a UINavigationController in which the RootViewController loads an external nib file.
    The nib file has 8 buttons with 8 corresponding Outlets and 1 Action. I've created a class file for the .nib and assigned it to the nib's File Owner. I've then reconnected the view to the file owner.
    The RootViewController displays the nib fine. However, if I connect the Outlets to the buttons or "click" a button which executes the action, I get something like "[RootViewController placeCall:]: unrecognized selector sent to instance" in the Debugger Console.
    Remember, the outlets and the action are/in the class file for the nib, not the class file for the RootViewController.
    From the debugger, it seems as if the the RootViewController can't find any of my outlets even though they're attached in the IB.
    Any suggestions?
    Thanks.

    The class of the RootViewController needs to be set in two places since the object is created in MainView.xib and is also represented by the File's Owner proxy object in the nib that defines your controls. Make sure it's set to the same class name in both nibs.

  • UITabBar iPhone SDK

    Hi,
    I have a UITabBar app, but cannot get any images to display in it.
    I have created it like this
    viewController = [[MyViewController alloc] init];
    viewController.title = @"Title";
    viewController.tabBarItem.image = [UIImage imageNamed:@"Title.png"];
    where MyViewController is an derived class of UIViewController.
    The button appears but no image is displayed.
    My question is do the images have to be a certain size for this to work?
    Thanks
    Adrian (very new to mac os programming)

    Hi guys, and thanks for your replys.
    I have added the image to the project, and now I have made it 29 x 29 pixels.
    its still not displaying correctly. :o(
    it just puts a blue box on the screen (if its the selected item - grey box if not).
    I am wondering if its an image format problem? I am editing the image using GIMP.
    This is becoming very frustrating.
    Thanks.
    Adrian

  • [iPhone] Setting UINavigationController children in XIB

    Is there any way to do the equivalent of:
    \[myUINavigationController initWithRootViewController:myViewController\]
    in Interface Builder?
    Message was edited by: Lawrence Wang

    When you have the representation of your Navigation Controller, you have the view that appears in gray surrounded by a dotted rounded rectangle.
    If you click on that, the Inspector shows you the properties of the view.
    In the "Attributes" tab (use cmd + 1 to display) you have two attributes.
    First is the title and the other is drop down list for the nib file name.
    Initially that list is empty, but once you have designed the nib file of your viewcontroller and added it to your project, you'll be able to select it there.
    Hope this helps

  • IPhone Dev: Tab Bar Controller with nested Navigation Controller

    I want to have a tab bar with 2 views. The first view is a navigational one. I know the view can be loaded in from an external nib and I can set the first view to a navigation controller.
    My question is: can this navigation controller in the external nib instead? Ideally I want to separate it out so the tab bar loads in the external nib (that has the navigation controller). Is this possible? or the only approach is to simply have to set the view controller to a navigation controller?

    Hey, this writing an app that uses the Tab View Controller in conjunction with Navigation View Controllers is driving me bats. I took a sample program which worked well, added a nib file for a basic view that only had a label on it then:
    * I created a view controller class to work with it.
    * I added code to add create a navigation controller.
    * Added my new view controller to the navigation controller
    * added this nav controller to the array with the other stuff for the tab view controller.
    * RUN
    Everything seems to work as far as all the existing stuff. And the title for my new "tab" shows up on the More tab.
    But when I click on it (in the simulator) the program crashes. It could be how I set up the nib file I made is wrong.
    I posted the code on my web site. Here is the URL:
    http://chomer.com/iphonesample_code/05a_-_Brightness_ToolbarSwatches.zip
    Please have a look. Its probably something small and stupid that I missed.
    Regards,
    Orville

  • [iPhone] Custom Colors in UITabBar

    Hello all,
    our customers CI consists of mostly reddish colors. The default blue in the tab bar is totally a no-go here, the customer will just reject that. While I am able to put custom views in a navigation bar I haven't found anything like that in the tab bar api. Will I really have to roll my own tab bar just because of this?
    Thanks + regards,
    Sebastian Mecklenburg

    thanks again. now i created a category for UITabBarItem where i re-implement the setImage method with something like
    -(void)setImage:(UIImage*)image {
    if(image == NULL) //might be called with NULL argument
    return;
    _image = [image retain];
    _unselectedImage = [image retain];
    UIImage* img = createSelectedImage(image)
    _selectedImage = [img retain];
    which seems to work.
    and yes, apple's intentions are quite clear and laudable and you gave a reasonable explanation for a nice theory. however, this theory comes to a screeching halt when it hits a brick wall in form of a big company's chief marketing officer who gives a rats bum for user interface design theory and consistency and stuff. for him, a perfect world would be pink with the company's logo printed everywhere. and in my opinion apple should keep in mind that not everything can go their way, that they can hand out guidelines but that they have to provide alternatives.

  • IPhone SDK: auto-rotation sets wrong bounds in view?

    Hi all,
    Can anybody confirm if this is a bug in the iPhone SDK? I have a ViewController that defines as its view a DimensionsLogger, which is a trivial subclass of UIView that just logs its frame, bounds and center properties when layoutSubviews is invoked.
    When I set this view as the root view in my application, the dimensions are logged like so (portrait mode):
    Bounds: (0.000000, 0.000000) x (320.000000, 460.000000)
    I rotate it to landscape mode and the bounds are logged:
    Bounds: (0.000000, 0.000000) x (390.000000, 390.000000)
    Bounds: (0.000000, 0.000000) x (480.000000, 300.000000)
    Then back to portrait mode:
    Bounds: (0.000000, 0.000000) x (390.000000, 390.000000)
    Bounds: (0.000000, 0.000000) x (320.000000, 460.000000)
    So far, so good.
    When I add my DimensionLogger + ViewController to a NavigationController, however, the same process (repeated several times) yields the following output:
    Bounds: (0.000000, 0.000000) x (320.000000, 416.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 346.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 358.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 358.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 346.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 346.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 358.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 358.000000)
    Bounds: (0.000000, 0.000000) x (390.000000, 346.000000)
    The bounds value never returns to the original dimensions.
    Am I missing something, or is this a bug? The practical consequence of this is that it seems impossible to combine the following 3 UI elements:
    - "anchoring" something to the bottom of a view, like a UIToolbar (NOT a tabbar)
    - Nesting that view in a UINavigationController
    - Supporting portrait and landscape interface orientation.
    Also, if I file this as a bug, is there any way to search the bug report tool to see if this has already been filed? I've logged into the tool and I see some search functionality but it only seems to search bugs I've previously filed.
    Thanks,
    Russ

    Just wanted to add that I've tried this in the simulator and on a provisioned iPod touch, same results on both.
    Russ

Maybe you are looking for

  • PSE 10 Editor never opens...

    Hi folks, I've used PSE since version 1 and hardly ever a problem until v 10. It is installed in the default locations in win7 64bit. I've installed it three times so far. I try to start the Editor from it's exe file to aviod the Unwelcome screen. v

  • Round trip clearing adobe form field values not binded to webdynpro context

    Hi , I have developed a webdynpro ABAP application with Interactive form. I'm calling a webservice on 'exit event' of the one of the form fields. Once webservice is executed, Im filling a table with 300 rows which is in the form. The table fileds are

  • OS 9 Compatability

    This question is asked on the off chance that I'm missing something. I cannot get this eMac to boot from anything that has OS 9 on it; Retail CD, or Firewire Hard drive (all 9.2.2). eMac 1000mhz currently running 10.4.11 Are there some of these machi

  • Which of these two CSS syntaxes is the right one?

    padding: 0 0 130px 0; or... padding: 0px 0px 130px 0px;

  • 3G Connectivity?? Please Help!!

    Okay, so I got my droid X in the mail about a month ago and activated it and all that jazz in new york, where i live, however, I spend the summers in West Virginia. When I am in New York, Ocean City, and Virginia, I can connect to all of the features