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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:57:44+00:00 2026-05-23T05:57:44+00:00

How to access(get the user selection) from UIpickerview components in different UIViews (NOT using

  • 0

How to access(get the user selection) from UIpickerview components in different UIViews (NOT using the Interface builder)?

Thanks.

Here is my code:

UIView *myView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
UIView *myView2 = [[UIView alloc] initWithFrame:CGRectMake(20, 250, 100, 100)];

[myView1 setBackgroundColor:[UIColor blueColor]];
[myView2 setBackgroundColor:[UIColor redColor]];

[self.view addSubview:myView1];
[self.view addSubview:myView2];

UIPickerView *pickerView1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
pickerView1.delegate = self;
pickerView1.showsSelectionIndicator = YES;
[myView1 addSubview:pickerView1];

UIPickerView *pickerView2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
pickerView2.delegate = self;
pickerView2.showsSelectionIndicator = YES;
[myView2 addSubview:pickerView2];

I have this callback, but once I put the pickerView in multiple UIViews it fails:

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"Selected Color: %@. Index of selected color: %i", [arrayColors objectAtIndex:row], row); 
} 

This is the problem (but don’t know the work around):

[self.view addSubview:pickerView1]; //<-- this works (able to get a response)
//[myView1 addSubview:pickerView1];  //<-- this fails 

Dont’t know why I have to have it in the main 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-05-23T05:57:45+00:00Added an answer on May 23, 2026 at 5:57 am

    Since both pickerviews have the same delegate, you need to differentiate between them in the delegate methods. One way to do this is by using the tag property.

    Set the tag property of each of your picker view’s. Then in your UIPickerView delegate method pickerView:didSelectRow:inComponent:, query the tag and respond accordingly.

    #define kVIEW1_PICKERVIEW_TAG 123
    #define kVIEW2_PICKERVIEW_TAG 456
    
    UIView *myView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
    UIView *myView2 = [[UIView alloc] initWithFrame:CGRectMake(20, 250, 100, 100)];
    
    [myView1 setBackgroundColor:[UIColor blueColor]];
    [myView2 setBackgroundColor:[UIColor redColor]];
    
    [self.view addSubview:myView1];
    [self.view addSubview:myView2];
    
    UIPickerView *pickerView1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
    pickerView1.delegate = self;
    pickerView1.tag = kVIEW1_PICKERVIEW_TAG;
    pickerView1.showsSelectionIndicator = YES;
    [myView1 addSubview:pickerView1];
    
    UIPickerView *pickerView2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
    pickerView2.delegate = self;
    pickerView2.tag = kVIEW2_PICKERVIEW_TAG;
    pickerView2.showsSelectionIndicator = YES;
    [myView2 addSubview:pickerView2];
    

    –

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    switch( pickerView.tag ) {
        case kVIEW1_PICKERVIEW_TAG:
           /* code */
            break;
        case kVIEW2_PICKERVIEW_TAG:
            /* code */
            break;
        default:
            break;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to get the user details from Twitter in iOS
Which permission needs my application to get access to the location of the user
I need to get a log of user access to our SQL Server so
I need to get access to the iTunes tags in an RSS feed using
i want to access or get the class which is present in different project.How
i am trying to get access to whitepages using YQL. Unfortunately i don't have
I'm not going to get specific here with code, because I don't feel like
How can I access UserId in ASP.NET Membership without using Membership.GetUser(username) in ASP.NET Web
How do i get access to a control (linkbutton in my case) that is
Is it possible to get access to the spell checker that is incorporated in

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.