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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:53:34+00:00 2026-06-02T00:53:34+00:00

I have a custom UIPickerView with three components that are dependent on one another

  • 0

I have a custom UIPickerView with three components that are dependent on one another (i.e., the second one shows values depending on what has been selected in the first one and the third is dependent on the first and second). I am getting the values that are shown in the UIPickerView out of an NSDictionary.

Everything works nicely, except, when I spin two of the components at the same time, the app sometimes crashes (no time to reload data). This is what my pickerView:didSelectRow:inComponent looks like:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{
    NSLog(@"Selecting row %d component %d", row, component);

    // When A is changed, we need to reload B and C
    if (component == 0) {

        [pickerView reloadComponent:1];
        [pickerView selectRow:0 inComponent:1 animated:YES];

        // need to reload the C after reloading B
        [self pickerView:pickerView didSelectRow:0 inComponent:1];

    }
    else if (component == 1) {
        [pickerView reloadComponent:2];
        [pickerView selectRow:0 inComponent:2 animated:YES];
    }
    [self updateSelection];
}

Is there a way to prevent the user from spinning more than one component of the picker at a time to prevent a crash?

Thanks!

  • 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-02T00:53:36+00:00Added an answer on June 2, 2026 at 12:53 am

    Good holy Jesus you call didSelectRow:component: recursively!

    I know that the way you handle parameters prevents it from going more than two levels deep, but still, don’t do that. Ever.

    There’s no way to prevent the user from spinning more than one component at a time. It is the joy of multitouch and iOS to set everything in motion and watch it all settle down into a consistent state. And because the spinner components take time to settle, the user can set them all atwitter using just one finger. You must learn to write your code accordingly.

    In this case, you want to delete all calls to didSelectRow:component: from within itself – it is to be called by the system only. You’re on the right track with your use of reloadComponent:, it’s just that you’re not reloading enough of them:

    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
        NSLog(@"Selecting row %d component %d", row, component);
    
        [self updateSelection];
    
        // When A is changed, we need to reload B and C
        if (component == 0) {
            [pickerView reloadComponent:1];
            [pickerView reloadComponent:2];
        } else if (component == 1) {
            [pickerView reloadComponent:2];
        }
    }
    

    I don’t know what your updateSelection does – presumably it sets the data model based on the value of pickerView. This is fine – but it needs to happen at the top of your method, so that when whichever of your titleForRow or viewForRow is called, it has the proper data to choose from. Also, from within any of those three (update,titleFor, viewFor) do not assert values into the picker! Just read from it.

    I think this is a good starting point for you, but you will have to tweak things a little here and there as you get closer to your goal. I think you will find that the key to Pickers is that they only assert didSelectRow:component: when one of the component spinner things settles down on a value, and they’re really good about continuing to spin if you reload them. Give this a shot and see if you can make some progress, send word back if you get stuck.

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

Sidebar

Related Questions

I have custom event that has several different subscribers who will all use the
I have custom gallery. Gallery represents items that are frame layout. There are one
I need a PickerView, that behaves like a normal UIPickerView, but only shows one
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have custom component that I can place in my layout file (XML) for
I have custom drupal module. I receive result from a webservice that I need
I have custom SiteMapProvider and RoleProvider that works together properly: IsAccessibleToUser returns false if
I have custom code inside of a SSRS report that needs to get the
I have custom exceptions in my django project that look like this: class CustomFooError(Exception):
I have a custom UIPickerView where I use: -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView

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.