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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:53:37+00:00 2026-05-29T04:53:37+00:00

what i am trying to do is to put two uipickers on the same

  • 0

what i am trying to do is to put two uipickers on the same view, i read somewhere that one of them should have its own separate delegate i tried to do so but i couldn’t make it work properly.

Some times when i run the application the second application just stops working with no errors on the console.

this is the .h file for the view:

@interface FirstViewController : UIViewController {

IBOutlet UIPickerView *cities;
NSMutableArray *array;
NSString *picked;
}

@property(nonatomic,retain) IBOutlet UIPickerView *cities;
@property(nonatomic,retain) IBOutlet NSMutableArray *array;

and here is the .m:

@implementation FirstViewController
@synthesize cities,array;

-(void) getCities:(NSString *)link{
    url=link;
    NSString *str=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
    if([str length]==0){
        [str release];
        return;
    }

    SBJsonParser *parser=[[SBJsonParser alloc] init];
    array=[[parser objectWithString:str] copy];
    [receivedData release];

}


- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { // This method needs to be used. It asks how many columns will be used in the UIPickerView 
    return 1; // We only need one column so we will return 1. 
}


- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { // This method also needs to be used. This asks how many rows the UIPickerView will have. 
    return [array count]; // We will need the amount of rows that we used in the pickerViewArray, so we will return the count of the array. 
} 


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { // what happens when selecting rows
    picked=[array objectAtIndex:row];
} 


- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //method asks for what the title or label of each row will be
    return [array objectAtIndex:row]; // We will set a new row for every string used in the array. 
} 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [sv setScrollEnabled:TRUE];
    [sv setContentSize:CGSizeMake(320, 800)];
    [self getCities:@"any url"];

    [super viewDidLoad];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload
{
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


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

@end

and for the second uipicker i added an nsobject to the view and changed its class to “SecondPickerDelegate” which i created before and this is its code:
.h

#import <UIKit/UIKit.h>


@interface FirstViewSecondPickerDelegate :  UIViewController<UIPickerViewDelegate>{

    IBOutlet UIPickerView *specialities;
    NSMutableArray *array;
    NSString *picked;
}

@property(nonatomic,retain) IBOutlet UIPickerView *specialities;
@property(nonatomic,retain) NSMutableArray *array;
@property(nonatomic,retain) NSString *picker;

@end

the .m file:

#import "FirstViewSecondPickerDelegate.h"
#import "JSON.h"


@implementation FirstViewSecondPickerDelegate
@synthesize specialities,array,picker;

-(void) getSpecialities:(NSString *)link{
    url=link;
    NSString *str=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
    if([str length]==0){
        [str release];
        return;
    }

    SBJsonParser *parser=[[SBJsonParser alloc] init];
    array=[[parser objectWithString:str] copy];
    for(int i=0;i<[array count];i++){
        NSLog(@"index %i",i);
        NSLog(@"value %@",[array objectAtIndex:i]);
    }


}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { // This method needs to be used. It asks how many columns will be used in the UIPickerView 
    return 1; // We only need one column so we will return 1. 
}


- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { // This method also needs to be used. This asks how many rows the UIPickerView will have. 
    return [array count]; // We will need the amount of rows that we used in the pickerViewArray, so we will return the count of the array. 
} 


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { // what happens when selecting rows
    picked=[array objectAtIndex:row];
} 


- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //method asks for what the title or label of each row will be
    return [array objectAtIndex:row]; // We will set a new row for every string used in the array. 
} 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        picked=@"1";
        [self getSpecialities:@"http://localhost:8080/Test/gs"];
    }


    return self;
}
/*
-(void) viewDidLoad{
    [super viewDidLoad];

}

*/

- (void)dealloc
{

    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{

    [super viewDidLoad];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

If any one has a working example for such case please help.

  • 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-29T04:53:39+00:00Added an answer on May 29, 2026 at 4:53 am

    You don’t need separate delegates for two UIPickerView‘s in the same view.

    Use the UIPickerView tag property, and then you can differentiate between them in delegate methods.

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

Sidebar

Related Questions

I am trying to put two different UIPopovers in one view. I'm fairly new
I'm trying to put in an exception in my web.config so that one page
I'm trying to put two buttons on the screen and set them up so
I'm trying to put two pictures in the QGraphicsScene . One is fixed and
I'm trying to put two divs on the right side of parent div one
I'm trying to put two web projects that needs to be installed in different
I'm trying to put two sliders in the same form ; but I can't
Hey. I'mm trying to put two points on a single map with same div
So I'm trying to put a LinearLayout that has two TextViews inside of a
I'm trying to put two blocks into one fixed-height block to create the following

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.