Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 948293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:13:16+00:00 2026-05-15T23:13:16+00:00

I’m trying to either add 3 custom buttons to my navigation controller toolbar on

  • 0

I’m trying to either add 3 custom buttons to my navigation controller toolbar on the top of my view or add a segmented control with 3 options. I have the following code on my app delegate for when i create my view controller(fwc) but the buttons dont appear.

/*
Set up the navigation controller for the Feeding Tab
*/

// instantiate the feedingViewController and set the title to Feedings
feedingViewController *fwc = 
[[feedingViewController alloc] initWithNibName:@"feedingViewController" 
                                           bundle:[NSBundle mainBundle]];
//fwc.title = @"Feedings";

// set the tab bar item up and add it as feedingViewController's tab bar item
UITabBarItem *feedingTabBarItem = 
[[UITabBarItem alloc] initWithTitle:@"Feedings" image:nil tag:0];
fwc.tabBarItem = feedingTabBarItem;
[feedingTabBarItem release];

// create a new nav controller for feedings and add root view
feedingNavController = [[UINavigationController alloc] init];

//Create the add button, need to change the selector to something though *****
UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                                     target:self 
                                                                     action:@selector(newFeeding)]; 
//self.navigationItem.rightBarButtonItem = add;


UIBarButtonItem *flexibleSpaceButtonItem = [[UIBarButtonItem alloc]
                                            initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                            target:nil action:nil];

// Create and configure the segmented control
UISegmentedControl *sortToggle = [[UISegmentedControl alloc]
                                  initWithItems:[NSArray arrayWithObjects:@"Ascending",@"Descending", nil]];

sortToggle.segmentedControlStyle = UISegmentedControlStyleBar;

sortToggle.selectedSegmentIndex = 0;

[sortToggle addTarget:self action:@selector(toggleSorting:)forControlEvents:UIControlEventValueChanged];

// Create the bar button item for the segmented control
UIBarButtonItem *sortToggleButtonItem = [[UIBarButtonItem alloc]initWithCustomView:sortToggle];

[sortToggle release];


// Set our toolbar items
feedingNavController.toolbarItems = [NSArray arrayWithObjects:
                     flexibleSpaceButtonItem,
                     sortToggleButtonItem,
                     flexibleSpaceButtonItem,
                     add,                    
                     nil];
feedingNavController.navigationController.navigationBarHidden=NO;

[sortToggleButtonItem release];
[add release];

// Push the feedingViewController on the nav stack and release it.
[feedingNavController pushViewController:fwc animated:NO];
[fwc release];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:13:17+00:00Added an answer on May 15, 2026 at 11:13 pm

    In order to use a UITabBar you would need a UITabBarController, which is different than the UINavigationController. A UITabBar has a fundamentally different use than a UISegmentedControl. It appears that the functionality you’re trying to implement is not appropriate for a UITabBar. In your question description you mention trying to add these buttons to the “navigation controller toolbar on the top.” A UINavigationController has a UINavigationBar, which is the bar that runs across the top, and a UIToolbar, which is the bar that appears at the bottom. The UIToolbar, by default, is set to hidden, but you get a UIToolbar for free whenever you create a UINavigationController (see the UINavigationController reference in Xcode).

    Apple’s NavBar demo shows how to put a UISegmentedControl into the UINavigationBar. Instead of a title, use a custom titleView to display the segmented control:

    fwc.navigationItem.titleView = sortToggle;
    

    If you want to put your add UIBarButtonItem in the UINavigationBar as well, you can use:

    fwc.navigationItem.rightBarButtonItem = add;
    

    Note that you shouldn’t actually go about trying to customize the UINavigationController’s navigation bar on your own. The proper way to customize is to have an individual view controller access it’s own navigationItem and set the titleView and rightBarButtonItem with the items you want.

    If you wish to approach your problem using a UIToolBar instead, meaning that your items will appear on the bottom of the screen, you can do something like this:

    // Assume UIBarButtonItem *add, UIBarButtonItem *sortToggleButtonItem, 
    // and UIBarButtonItem *flexibleSpaceButtonItem are allocated
    [fwc setToolbarItems:[NSArray arrayWithObjects:
                     flexibleSpaceButtonItem,
                     sortToggleButtonItem,
                     flexibleSpaceButtonItem,
                     add,                    
                     nil]];
    [feedingNavController setToolbarHidden:NO];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.