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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:48:01+00:00 2026-05-28T03:48:01+00:00

in one of my view controllers I want to use multiple pickers. Header file:

  • 0

in one of my view controllers I want to use multiple pickers.

Header file:

@interface MyTableController : TTTableViewController <UIActionSheetDelegate, UIPickerViewDataSource, UIPickerViewDelegate>{

    IBOutlet UIPickerView *picker1;
    IBOutlet UIPickerView *picker2;

    NSMutableArray *list1;
    NSMutableArray *list2;
}

@property(nonatomic,retain) UIPickerView *picker1, *picker2;

-(IBAction)togglePickerView1;
-(IBAction)togglePickerView2;

@end

Implementation file:

@implementation MyTableController

@synthesize picker1, picker2;

int row_index1 = 0;
int row_index2 = 0;

- (void)locationPicker:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
    if([pickerView isEqual: picker1]){
        row_index1 = row;
    }

    if([pickerView isEqual: picker2]){
        row_index2 = row;
    }
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

    if([pickerView isEqual: picker1]){
        return 1;
    }

    if([pickerView isEqual: picker2]){
        return 1;
    }         
    return 0;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if([pickerView isEqual: picker1]){
        return [list1 count];
    }

    if([pickerView isEqual: picker2]){
        return [list2 count];
    }  
    return 0;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent: (NSInteger)component{
    return [list objectAtIndex:row];
    if([pickerView isEqual: picker1]){
        return [list1 objectAtIndex:row];
    }

    if([pickerView isEqual: picker2]){
        return [list2 objectAtIndex:row];
    }

    return nil;
}

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {  

}

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {

    if (actionSheet.tag == 111) {
        picker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
        picker1.showsSelectionIndicator = YES;
        picker1.dataSource = self;
        picker1.delegate = self;  

        //Add picker to action sheet
        [actionSheet addSubview:picker1];
        [picker1 release];
    }else if(actionSheet.tag == 222){
        picker2 = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
        picker2.showsSelectionIndicator = YES;
        picker2.dataSource = self;
        picker2.delegate = self;

        //Add picker to action sheet
        [actionSheet addSubview:picker2];
        [picker2 release];
    }

    //Gets an array af all of the subviews of our actionSheet
    NSArray *subviews = [actionSheet subviews];

    [[subviews objectAtIndex:1] setFrame:CGRectMake(20, 266, 280, 46)]; 
    [[subviews objectAtIndex:2] setFrame:CGRectMake(20, 317, 280, 46)];
}

-(IBAction)togglePickerView1{
    UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"FLT", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"CANCEL", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"PICK", nil), nil];
    [asheet setTag:111];
    [asheet showInView:[self.view superview]]; //note: in most cases this would be just self.view, but because I was doing this in a tabBar Application, I use the superview.
    [asheet setFrame:CGRectMake(0, 117, 320, 383)];
    [asheet release];   
}

-(IBAction)togglePickerView2{
    //...  
    [asheet setTag:222];
    //...
}

- (void)loadView {
    [super loadView];
}

-(void)viewDidLoad{

    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"Button1" style:UIBarButtonItemStyleBordered target:self action:@selector(togglePickerView1)];

    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"Button2" style:UIBarButtonItemStyleBordered target:self action:@selector(togglePickerView2)];


    NSArray *myToolbarItems = [[NSArray alloc] initWithObjects: item1, item2, nil];                 

    [self setToolbarItems: myToolbarItems];
    [myToolbarItems release];

    list1 = [[NSMutableArray alloc] init];

    [list1 addObject:@"--"];
    [list1 addObject:@"Test1"];

    list2 = [[NSMutableArray alloc] init];

    [list2 addObject:@"--"];
    [list2 addObject:@"Test2"];
}


@end

My problem is that no matter which button I hit, it is always the picker1 that is triggered. Any ideas where the problem is?

  • 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-28T03:48:02+00:00Added an answer on May 28, 2026 at 3:48 am

    You are successfully creating two different pickers, and showing the correct one each time.

    The problem is, each picker has the same data in it.

    The first line in your data source titleForRow... method is this:

    return [list objectAtIndex:row];
    

    This ends execution of your data source method by returning a value, so both pickers will always show the same data, regardless of the rest of your code. list isn’t declared anywhere in your code above so I’m not sure what you are actually seeing on the screen.

    I have built a sample project using your code above and confirmed that this is the issue. Removing that line gives you two different pickers, with the different content in each one.

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

Sidebar

Related Questions

Want to use two models in one view. I have two controllers one for
I want to switch between multiple view controllers with a UIPageViewController . These view
Using storyboard, I have a table view controller containing multiple dynamic prototype cells. One
In one of my Controllers, I have multiple URLs that will ultimately render in
I have a long View Controllers hierarchy; in the first View Controller I use
This is a simple question: I have 2 different view controllers, and each one
Note: If you want to divide a view hierarchy into multiple subareas and manage
I want to use a UIScrollView to display multiple UIViews as the user scrolls
I have two view controllers and nibs. I populated one view controller with a
I have two view controllers. In one of them I have a UITextField within

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.