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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:02:07+00:00 2026-05-16T12:02:07+00:00

I am using two UIPickers in a view. first picker has 3 components and

  • 0

I am using two UIPickers in a view.
first picker has 3 components and second has one.
but when I select items, it shows correct items from first picker but always return first item from second picker regardless of selected row.
Please help.

here is the code I am using.

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
   if (pickerView == triplePicker) 
     return 3;
   else {
     return 1;
   }
}


-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
   if (pickerView == triplePicker) {  
      if (component == kColorComponent)
         return[colorList count];
      if (component == kClarityComponent)
         return[clarityList count];
      return[shapeList count];
   }
   else{
      return [listPickerItems count];
   }
}

-(NSString *)pickerView:(UIPickerView *)pickerView
            titleForRow:(NSInteger)row
           forComponent:(NSInteger)component 
{   
   if (pickerView == triplePicker) {  
      if (component == kColorComponent)
         return [colorList objectAtIndex:row];
      if (component == kClarityComponent)
         return [clarityList objectAtIndex:row];
      return [shapeList objectAtIndex:row];  
   }
   else{
      return [listPickerItems objectAtIndex:row];
   }
}

in buttonpressed event I have following for second picker to return the item selected:

NSInteger pickrow = [listPicker selectedRowInComponent:0];
NSString *picked = [listPickerItems objectAtIndex:pickrow];
  • 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-16T12:02:08+00:00Added an answer on May 16, 2026 at 12:02 pm

    I would definitely suggest using two separate delegates to handle two pickers.

    Aside from that, I’m going to guess that you’re using Interface Builder to set up your view. If that’s the case check if you have properly linked your listPicker with your File’s Owner. If listPicker would be nil, then selectedRowInComponent: would always return null (0 for NSInteger), hence would always select the first item in your array.

    EDIT: Some sample code for separate delegates:

    You need to create a second class to be your delegate, like this:

    FirstPickerDelegate.h

    #import <Foundation/Foundation.h>
    
    @class UntitledViewController;
    
    @interface FirstPickerViewDelegate : NSObject <UIPickerViewDelegate, UIPickerViewDataSource> {
        NSArray* values;
        IBOutlet UntitledViewController* viewController;
    }
    -(void) loadData;
    
    @property (nonatomic, retain) NSArray* values;
    @property (nonatomic, assign) IBOutlet UntitledViewController* viewController;
    
    @end
    

    FirstPickerViewDelegate.m

    #import "FirstPickerViewDelegate.h"
    
    
    @implementation FirstPickerViewDelegate
    @synthesize values;
    @synthesize viewController;
    
    -(id) init
    {
        if ( self = [super init] )
        {
            [self loadData];
        }
        return self;
    }
    
    -(void) loadData
    {
        NSArray* array = [[NSArray alloc] initWithObjects:@"first", @"second", @"third", nil];
        self.values = array;
        [array release];
    }
    
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return 1;
    }
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
        return [values count];
    }
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
        return [values objectAtIndex:row];
    }
    
    -(void) dealloc
    {
        self.values = nil;
        [super dealloc];
    }
    @end
    

    Your ViewController (UntitledViewController here, sorry about the name):

    #import <UIKit/UIKit.h>
    
    @class FirstPickerViewDelegate;
    @interface UntitledViewController : UIViewController {
        IBOutlet UIPickerView* firstPicker;
        IBOutlet FirstPickerViewDelegate* firstDelegate;
    }
    
    @property (nonatomic, retain) IBOutlet UIPickerView* firstPicker;
    @property (nonatomic, retain) IBOutlet FirstPickerViewDelegate* firstDelegate;
    
    @end
    

    Basically you need to drop an NSObject on your object list, and change it’s class to FirstPickerViewDelegate, then make connections like this:
    alt text

    I feel I overelaborated this time, but I’m in a good mood today so whatever 😛

    About the main question: double check that listPicker is not nil at the time of pressing the button, if it is not, try to use

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    

    to track down the error.

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

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • 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 Git add + git commit -m will just commit those… May 16, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer You can use the Flex Framework to make commercial products… May 16, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer Oracle sequences work that way. They only guarantee uniqueness but… May 16, 2026 at 2:00 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

Related Questions

This is my first time using IB, but after spending a one or two
I am using two different jQuery plugins that I'm trying to combine. First I'm
I am working on a core data using app and one of the views
I have a dependent UIPicker that loads the values into its two components from
Using two 2.0 emulators and the native messaging application - if I send a
Using two ScriptManagers(ASP.Net and Telerik) will effect the page performance ? I have both
Possible Duplicate: Implement Stack using Two Queues I want the most efficient way in
I am using jQuery.ui.dialog.js to show the modal pop up.. But this Jquery.ui.dialog.js is
I'm crossfading between two views using UIView animation. I've noticed the following surprising fact:
I am using the following javascript to animate two slideshows using the nivo slider

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.