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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:55:41+00:00 2026-06-11T17:55:41+00:00

Using objC, it seems that there is a method called numberOfComponentsInPickerView which you can

  • 0

Using objC, it seems that there is a method called numberOfComponentsInPickerView which you can use to change the number of components in a UIPickerView. Once this is used to change the number of components you would then reload the components to “refresh” the Picker. i.e. [picker reloadAllComponents];

My question is how would I do this using MonoTouch? I am new to Mono, and after searching through all the methods and properties on my picker object, I can’t seem to find this method.

Here is how I am creating my UIPickerView:

public class PeopleModel : UIPickerViewModel {
        static string [] names = new string [] {
            "item1",
            "item2",
            "item3",
            "item4",
            "item5",
            "Custom"
        };

        ActionSheetPickerExampleViewController pvc;
        public PeopleModel (ActionSheetPickerExampleViewController pvc) {
            this.pvc = pvc;
        }

        public override int GetComponentCount (UIPickerView v)
        {
            return 2;
        }

        public override int GetRowsInComponent (UIPickerView pickerView, int component)
        {
            if (component == 0) {
                return names.Length;
            } else {
                return 50;
            }
        }

        public override string GetTitle (UIPickerView picker, int row, int component)
        {
            if (component == 0)
                return names [row];
            else
                return row.ToString ();
        }

        public override void Selected (UIPickerView picker, int row, int component)
        {
            pvc.diskLabel.Text = String.Format ("{0} - {1}",
                                            names [picker.SelectedRowInComponent (0)],
                                            picker.SelectedRowInComponent (1));
            Console.WriteLine (names[picker.SelectedRowInComponent(0)]);
            if (names [picker.SelectedRowInComponent(0)] == "Custom") {
                Console.WriteLine ("Custom selected!");
                picker.ReloadComponent(1);
                using(var alert = new UIAlertView("Select value", "Select custom disk speed",null,"OK","Button2"))
                {
                    alert.Show ();
                }

            }
        }

        public override float GetComponentWidth (UIPickerView picker, int component)
        {
            if (component == 0)
                return 240f;
            else
                return 40f;
        }

        public override float GetRowHeight (UIPickerView picker, int component)
        {
            return 40f;
        }
    }

So the above is the class, then I am creating the picker on an action sheet like this:

actionSheetPicker = new ActionSheetPicker (this.View);
        actionSheetPicker.Title = "Choose disk speed:";
        actionSheetPicker.Picker.Model = new PeopleModel (this);
        actionSheetPicker.Picker.Hidden = false;

Essentially, I am looking at adding another component to this Picker, only when the value of “Custom” is selected in the first component column, and then allowing the user to choose a value from this component as long as “Custom” is selected in the first component. Is this possible? I know how to change the number of components before the picker is created by returning a different number with “GetComponentCount”, it is just changing this on the fly once the picker is already created, that I am unsure of.

Thanks for any assistance!

  • 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-06-11T17:55:42+00:00Added an answer on June 11, 2026 at 5:55 pm

    I made a few changes to your PeopleModel to track if Custom is selected, and if it is showing a third component:

    public class PeopleModel : UIPickerViewModel
        {
            bool _custom;
            static string[] names = new string [] {
                "item1",
                "item2",
                "item3",
                "item4",
                "item5",
                "Custom"
            };
    
            ActionSheetPickerExampleViewController pvc;
            public PeopleModel (ActionSheetPickerExampleViewController pvc) {
                this.pvc = pvc;
            }
    
            public override int GetComponentCount (UIPickerView v) {
                if (_custom)
                    return 3;
                return 2;
            }
    
            public override int GetRowsInComponent (UIPickerView pickerView, int component) {
                if (component == 0) {
                    return names.Length;
                } else if (component == 1) {
                    return 50;
                } else
                    return 3;
            }
    
            public override string GetTitle (UIPickerView picker, int row, int component) {
                if (component == 0)
                    return names [row];
                else if (component == 1)
                    return row.ToString ();
                else
                    return row.ToString ();
            }
    
            public override void Selected (UIPickerView picker, int row, int component) {
                pvc.diskLabel.Text = String.Format ("{0} - {1}",
                                                    names [picker.SelectedRowInComponent (0)],
                                                    picker.SelectedRowInComponent (1));
                Console.WriteLine (names [picker.SelectedRowInComponent (0)]);
                _custom = names [picker.SelectedRowInComponent (0)] == "Custom";
                picker.ReloadAllComponents ();
    
            }
    
            public override float GetComponentWidth (UIPickerView picker, int component) {
                if (component == 0)
                    return 240f;
                else
                    return 40f;
            }
    
            public override float GetRowHeight (UIPickerView picker, int component) {
                return 40f;
            }
        }
    

    I think this is what you were trying to accomplish. The method ReloadAllComponents() is a member of UIPickerView.

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

Sidebar

Related Questions

I'm successfully using yajl-objc along with ASIHTTPRequest in an iPhone project that does network
I'm using C structs in objc and I've created a function that assembles the
I'm using this library: PB for ObjC http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers . The problem is I can't
Using Objective-C++, can I write a C++ IsObjectiveCClass<T> template metafunction such that IsObjectiveCClass<T>::value is
I want to add scripting support for an Objective-C project using the objc runtime.
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using the documentation provided by Apple to create an application preferences window that doesn't
The golden rule of using NSNotification seems to be call removeObserver before the observer
Where can I find a good detailed tutorial using sskeychain to store and retrieve
I'm generating a video from a Unity app on iOS. I'm using iVidCap, which

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.