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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:29:51+00:00 2026-05-27T03:29:51+00:00

I am attempting to use a UISegmentedControl to control the sort order of my

  • 0

I am attempting to use a UISegmentedControl to control the sort order of my table, in particular I want to register a tap on a segment that is already selected (to inverse my sort). As such, I am trying to raise an UIControlEvent.ValueChanged event whenever any segment is tapped.

I have overridden SelectedSegment from UISegmentedControl and am using this custom class for my element in xcode, however, it appears as though this code is not called when the the Segment control is tapped (It is called when the view is loaded though =S).

[Register("ReselectableSegment")]
public class ReselectableSegment : UISegmentedControl
{
    static Selector selInit       = new Selector("init");  

    [Export("init")]  
    public ReselectableSegment()  
        : base(NSObjectFlag.Empty)  
    {  
        Handle = Messaging.IntPtr_objc_msgSend(this.Handle,  
            selInit.Handle);  
    }  

    public ReselectableSegment (IntPtr handle) : base(handle){}

    public override int SelectedSegment
    {
        [Export ("SelectedSegment:")]
        set { 
            if(this.SelectedSegment == value)
                this.SendActionForControlEvents(UIControlEvent.ValueChanged);

            base.SelectedSegment = value;
        }
    }
}

This question has been asked before at: UISegmentedControl register taps on selected segment, however that question is for ObjC and this question is for C#/Monotouch.

  • 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-27T03:29:52+00:00Added an answer on May 27, 2026 at 3:29 am

    The last answer of the question link you provided contains the best (well working) answer (I upvoted it, you should too ;-).

    note: from the comments it looks like the previous answers were (maybe) working on iOS4 but not on iOS5.

    Here’s the code to do what you’re looking for. I used the RectangleF .ctor to test it, you might have to add your own .ctor if you’re using something else (but it’s not as complex as your original code, e.g. no selector should be needed to subclass this).

        class MyUISegmentedControl : UISegmentedControl {
    
            public MyUISegmentedControl (RectangleF r) : base (r) {}
    
            public override void TouchesBegan (NSSet touches, UIEvent evt)
            {
                int current = SelectedSegment;
                base.TouchesBegan (touches, evt);
                if (current == SelectedSegment)
                    SendActionForControlEvents (UIControlEvent.ValueChanged);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to use a table() function on an object in order to
In attempting to use std::select1st from <functional> in a VS2008 project I found that
Attempting to use asp.net mvc's Action Result of File. So it would seem that
I am attempting to use XMLParse against content that is not valid xhtml. In
I'm attempting to use the code from http://www.codeproject.com/Articles/20165/CheckBox-Header-Column-For-DataGridView in order to add a CheckBox
I am attempting to use an Ant build script to build a project that
I'm attempting to use a form post to add rows to a mySQL table.
I'm attempting to use a form post to add rows to a mySQL table.
I'm attempting to use a 3rd party service that uses OAuth 1.0a and requires
I'm attempting to use Fogbugz's BugzScout in order to automatically submit unhanded application exceptions

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.