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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:56:11+00:00 2026-05-13T11:56:11+00:00

I have a core data based app I am working on, that uses an

  • 0

I have a core data based app I am working on, that uses an EditingViewController to control a number of different UI elements that get input from the user which describe attributes of an object that is subsequently stored within my app. The EditingViewController.xib file has such elements as a datePicker, textField, numberSlider, and where my problem is coming from a UIPickerView, that are all controlled within one view using .hidden = YES/NO; expressions. My problem is that I need to populate a UIPickerView in two seperate screens, that need to have two different NSMutableArray sources. Inside my viewDidLoad method I setup my first NSMutableArray:

listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObject:@"Greenland"];
[listOfItems addObject:@"Switzerland"];
[listOfItems addObject:@"Norway"];
[listOfItems addObject:@"New Zealand"];
[listOfItems addObject:@"Greece"];
[listOfItems addObject:@"Rome"];
[listOfItems addObject:@"Ireland"];

And after that, I populate my UIPickerView *picker with this code:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)picker;
{
    return 1;
}

- (void)pickerView:(UIPickerView *)picker didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
    label.text= [listOfItems objectAtIndex:row];// The label is simply setup to show where the picker selector is at
}

- (NSInteger)pickerView:(UIPickerView *)picker numberOfRowsInComponent:(NSInteger)component;
{
    return 8;//[listOfItems count];

}

- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent: (NSInteger)component;
{
    return [listOfItems objectAtIndex:row];
}

And that works fine for the first attribute and array. So then after that, when a different uitableviewcell is selected, the picker is hidden picker.hidden = YES; and I need to have another picker, picker2 show up with a different array of information. But when I try and duplicate the process, by setting up a whole new picker, calling it picker2, and trying to populate it with a different NSMutableArray that I created right next to the first one (again, all because in my EditingViewController it’s all part of the same view, just calling different UI elements depending on the view) I can’t get picker2 to populate with the new array. I don’t know how to set it up so that my two different arrays can be populated. Do I need two picker views? Can it be done with just one? What is the proper syntax in the - (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent: (NSInteger)component; method to make the two arrays viewable seperately? I hope someone can help me out on this, thank you in advance!

  • 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-13T11:56:11+00:00Added an answer on May 13, 2026 at 11:56 am

    You are asking to use the same object as the delegate for two pickers.

    In each of the delegate methods, the picker is provided as the first argument for this purpose. You can check which picker is passed in and return the appropriate data for that picker.

    For example, if you add a property for the first picker named “pickerOne” and you second mutable array is called “arrayTwo”, the delegate methods would look like this:

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)picker;
    {
        return 1; // assuming both pickers only have 1 component
    }
    
    - (void)pickerView:(UIPickerView *)picker didSelectRow:(NSInteger)row inComponent: (NSInteger)component
    {
        // The label is simply setup to show where the picker selector is at
        if (picker == self.pickerOne) {
            label.text= [listOfItems objectAtIndex:row];
        } else {
            label.text= [arrayTwo objectAtIndex:row];
        }
    }
    
    - (NSInteger)pickerView:(UIPickerView *)picker numberOfRowsInComponent:(NSInteger)component;
    {
        if (picker == self.pickerOne) {
            return [listOfItems count];
        } else {
            return [arrayTwo count];
        }
    }
    
    - (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent: (NSInteger)component;
    {
        if (picker == self.pickerOne) {
           return [listOfItems objectAtIndex:row];
        } else {
            return [arrayTwo objectAtIndex:row];
        }
    }
    

    Also, you can populate your array like this (if you just have a static list of strings, the array does not need to be mutable):

    listOfItems = [[NSArray alloc] initWithObjects:@"Baptisms",@"Greenland",@"Switzerland",@"Norway",@"New Zealand",@"Greece",@"Rome",@"Ireland",nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't do that. It says "procedure of object", not… May 14, 2026 at 8:41 pm
  • Editorial Team
    Editorial Team added an answer DynamicActivity and the toolbox were basically not designed to work… May 14, 2026 at 8:41 pm
  • Editorial Team
    Editorial Team added an answer Compiler warnings tend to be about things that are either… May 14, 2026 at 8:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.