0

I'm trying to add some button to the toolbar of my navigationController: i see the toolbar, but without the buttons. This is the portion of my code where I set the toolbar...

(this is my AppDelegate)

// Create a table view controller
    RootViewController *rootViewController = [[RootViewController alloc]
                                              initWithStyle:UITableViewStyleGrouped];

    rootViewController.managedObjectContext = context;
    rootViewController.entityName = @"County";

    //Navigation Controller
    UINavigationController *aNavigationController = [[UINavigationController alloc]
                                                     initWithRootViewController:rootViewController];

    self.navigationController = aNavigationController;


    //Barbuttons
    UIBarButtonItem *homeButton;
    homeButton = [[[UIBarButtonItem alloc] initWithTitle:@"         Inizio         " style:UIBarButtonItemStyleBordered target:self action:@selector(home)] autorelease];

    UIBarButtonItem *barButton;
    barButton = [[[UIBarButtonItem alloc] initWithTitle:@"  Funzioni online   " style:UIBarButtonItemStyleBordered target:self action:@selector(caricamappa)] autorelease];

    UIBarButtonItem *creditsButton;
    creditsButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"credits2.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(credits)] autorelease];    

    NSArray *baritems = [NSArray arrayWithObjects: homeButton, barButton, creditsButton, nil];

    [window addSubview:[navigationController view]];
    [self.navigationController.toolbar setItems:baritems];
    [self.navigationController setToolbarHidden:NO];


    [window makeKeyAndVisible];

    [rootViewController release];
    [aNavigationController release];

Any idea about my mistake?

2 Answers 2

1

You should add buttons to navigationItem property of your rootViewController, not to the toolbar of navigation controller. Something like:

rootViewController.navigationItem.rightBarButtonItems = barItems;
Sign up to request clarification or add additional context in comments.

Comments

0

Check out the documentation, especially this part:

Management of this toolbar’s contents is done through the custom view controllers associated with this navigation controller. For each view controller on the navigation stack, you can assign a custom set of toolbar items using the setToolbarItems:animated: method of UIViewController.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.