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

  • SEARCH
  • Home
  • 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 6060465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:49:44+00:00 2026-05-23T08:49:44+00:00

I want to know if it is possible to add UIBarButtons to a SegmentedControl.

  • 0

I want to know if it is possible to add UIBarButtons to a SegmentedControl. It compiles but gives a runtime error:

-[UIBarButtonItem isEqualToString:]: unrecognized selector sent to instance 0x4b4fcc0

Here is my code.

UIBarButtonItem *atolButton = [[UIBarButtonItem alloc] initWithTitle:@"A to L"
      style:UIBarButtonItemStyleBordered target:self action:@selector(atol:)];

UIBarButtonItem *ltozButton = [[UIBarButtonItem alloc] initWithTitle:@"L to Z"
      style:UIBarButtonItemStyleBordered target:self action:@selector(ltoz:)];

NSArray *titleButtons = [NSArray arrayWithObjects: atolButton, ltozButton, nil];

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:titleButtons];
self.navigationItem.titleView = segmentedControl;
[segmentedControl release];
...

- (void)atol:(id) sender {
NSLog(@"atol called");  
}

- (void)ltoz:(id) sender {
    NSLog(@"ltoz called");
}

I have been able to make it work with the following code

NSArray *itemArray = [NSArray arrayWithObjects: @"a to l", @"l to z", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 1;
[segmentedControl addTarget:self action:@selector(atol:)
     forControlEvents:UIControlEventValueChanged];

self.navigationItem.titleView = segmentedControl;

[segmentedControl 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-23T08:49:45+00:00Added an answer on May 23, 2026 at 8:49 am

    UISegmentedControl inherits from UIControl which inherits from UIView, so you can add subViews to it as you would to a UIView.

    However, the segmented aspect is quite different. Each segment has an image property and title property, but that’s all.

    When you invoke initWithItems:, this must be an NSArray of UIImages or NSStrings.

    I have no idea what you’re trying to do that compels you to add buttons to a segmented controller, but I encourage you instead to set the title and image properties of the UISegmentedController and the customize the action in whatever method the controller is meant to trigger. For example:

    -(void)segmentAction:(UISegmentedController *)segment {
        if (segment.selectedSegmentIndex == 0) {
            [self atol];
        } else {
            [self ltoz];
        }
    }
    

    I have no idea what you cannot accomplish this way that you wish to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to know is this possible to add a searchbar in UItoolbar
Hello I want to know if it's possible to add widgets to a CRUD
just want to know is it possible to add Google Search Engine in my
I just want to know, whether it is possible for me to add zoom
I want to know if it is possible to let compiler issue a warning/error
I want to know if it is possible to add properties to the event
I know it is possible to add new CSS classes definitions at runtime through
I want to know if it is possible to add a javascript <script type=text/javascript>blahblah</script>
I want to know if it's possible to add an Iframe Element in ATK4
I want to know if it is possible to add multiple handlers for the

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.