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 6775779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:56:51+00:00 2026-05-26T15:56:51+00:00

I have a UISegmentedControl whose Value changed event is wired up in Interface Builder

  • 0

I have a UISegmentedControl whose “Value changed” event is wired up in Interface Builder to call my controller’s -(IBAction)segmentChangeAction:(id)sender;

When the user taps on the control to change the selected segment, as expected segmentChangeAction is called whether in iOS4 or iOS5.

When I programmatically change the selected segment through segmentedControl.selectedSegmentIndex = newIndex;, on iOS4 segmentChangeAction is called and the segment reflects the new selection. However on iOS5 segmentChangeAction is not called, yet the segment does reflect the new selection.

Is this a change in iOS5? Is there anything I can do to get segmentChangeAction called on iOS5 when I programmatically change the selection?

  • 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-26T15:56:52+00:00Added an answer on May 26, 2026 at 3:56 pm

    This is a change in iOS 5 in order for UISegmentedControl to be consistent with all other controls.

    The idea is that the action should only fired automatically as a result of user interaction. Prior to iOS 5, UISegmentedControl‘s actions would be fired because of user interaction and programmatic interaction. However, initiating the change programmatically means that you can also do [myControl sendActionsForControlEvents:UIControlEventValueChanged] yourself.

    However, you have to be careful with this. Say you do:

    [segmentedControl setSelectedSegmentIndex:newIndex];
    [segmentedControl sendActionsForControlEvents:UIControlEventValueChanged];
    

    If you build and run this on iOS 5, it works as you expect. If you build and run this on iOS 4, you’ll get your actions fired twice (once when you setSelectedSegmentIndex and again when you sendActions...).

    The way around this is to do some sort of guard. This could be a runtime check to indicate that you’re running on an iOS 5+ device, or could even be something more mundane, like this:

    // changingIndex is a BOOL ivar
    changingIndex = YES;
    [segmentedControl setSelectedSegmentIndex:newIndex];
    changingIndex = NO;
    [segmentedControl sendActionsForControlEvents:UIControlEventValueChanged];
    

    and then in your action method…

    - (void)segmentedControlSelectedIndexChanged:(id)sender {
      if (!changingIndex) {
        // your action code here, guaranteed to only run as a result of the sendActions... msg
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UISegmentedControl that has 6 segments which I created in Interface Builder.
I currently have a UISegmentedControl set to add/remove table view cells when its value
I have a UISegmentedControl that has six segments, I want them to call a
I have a UISegmentedControl on a black UIToolbar. I have set the style to
I have a checklist in a UITableView and I have a UISegmentedControl with Select
I was wondering what the best approach in order to have a UISegmentedControl appears
I am new to iPhone development. I have created UISegmentedControl having 2 segments. I
I am currently adding a UISegmentedControl to the toolbar in the navigation controller programmatically
I have added a UISegmentedControl in my application. None of the buttons are selected
I have a situation where i have a single UITableView and a single UISegmentedControl

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.