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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:51:53+00:00 2026-06-12T09:51:53+00:00

I have created a ViewController containing one picker. Its view is triggered to appear

  • 0

I have created a ViewController containing one picker. Its view is triggered to appear and populate the picker with one of four data arrays, depending on which one of four buttons has been pressed in the superview. I gave the subview an int property called pickerType, which I then set within the button code, like so:

    - (IBAction)chooseDepType:(id)sender
    {

        if (pickerView==nil)
        {
           pickerView = [[Picker alloc] initWithNibName:@"Picker" bundle:nil];
           //send message to next view telling which array to load in picker
           pickerView.pickerType=1;
        }
        [self.view addSubview:pickerView.view];
    }

The other button methods look the same, except that the pickerType is set to a different value.
Then, in the subview, I set up the datasource and delegate methods like so:

   -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
    {
        if(pickerType_ ==1)
        {
            // return the appropriate number of components, for instance
            return 1;
        }
    }

The problem I have is that even though I am setting pickerView to a new value in each button’s code, my subview is not recognizing that the value has changed. Basically, no matter which button I press, it shows me a picker filled with the data corresponding to the first button I pressed. To complicate matters, perhaps, the superview is a Detail view in a Master-Detail template.

pickerType property is created like this:

    @property (assign) int pickerType;

    @synthesize pickerType=pickerType_;

I am using ARC. I don’t know if this is a dumb programming error on my part, or has something to do with the lifecycle of a view.

  • 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-12T09:51:55+00:00Added an answer on June 12, 2026 at 9:51 am

    Since you are checking whether your Picker has already been created:

    if (pickerView==nil)
    

    before setting the type:

        pickerView.pickerType=1;
    

    the next time you press a button, pickerView already exists, execution skips over the body of the if and the type is not changed.

    To fix this, move the type-setting statement out of the if block.

    Incidentally, if you have four buttons that all do almost exactly the same thing, you can have them all trigger the same IBAction and distinguish which was pressed by their tag properties:

    - (IBAction)showPicker: (id)sender
    {
        if (pickerView==nil)
        {
           pickerView = [[Picker alloc] initWithNibName:@"Picker" bundle:nil];
        }
        // Each button's tag could correspond exactly to the appropriate pickerType,
        // or have any other meaning you choose.
        [pickerView setPickerType:[sender tag]];
        [self.view addSubview:pickerView.view];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two viewController classes such that one is superclass of another.i have
I have created an application with multiple views. I have my main view (ViewController.h)
In my ViewController I have created a view which contains a button and a
I want to add Scroll View into ViewController. I have created viewcontroller by code.
I have a ViewController and UIWebView created in Interface Builder in it. I fill
I have a storyboard setup as a Tabbed Application with first view controller containing
I'm trying to create horizontal scroll view(s). Each view containing one image. [done] Initially
I have setup a basic test app that displays a view containing a label,
I have to upgrade one existing application and neeed to split its existing UI
I have a view containing a number of UIButtons Tom and Jerry, The Lion

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.