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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:52:25+00:00 2026-06-08T20:52:25+00:00

I have a problem with my UIPickerView. I have 3 values in it EU

  • 0

I have a problem with my UIPickerView.
I have 3 values in it EU AP and NA.
When I start the app EU seems to be selected but when I make a NSLog(@"%@", [regions objectAtIndex:row]); I only get back (null),
now when I touch the UIPickerView the EU value is selected and I get "EU" back from a NSLog.

My question is:

How can I define a default value which is selected (not only the label) when the user only starts the app and touches nothing.

Edit: Here is my code to get the selected item:

#pragma mark -
#pragma mark PickerView DataSource

- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    return [regions count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component
{
    return [regions objectAtIndex:row];
}

#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
      inComponent:(NSInteger)component
{

                selectedRegion = [[NSString alloc] initWithFormat:
                              @"%@", [regions objectAtIndex:row]];
    NSLog(@"%@", selectedRegion);


}
  • 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-06-08T20:52:28+00:00Added an answer on June 8, 2026 at 8:52 pm

    TL:DR version:

    //Objective-C
    [self.picker selectRow:2 inComponent:0 animated:YES];
    //Swift
    picker.selectRow(2, inComponent:0, animated:true)
    

    Either you didn’t set your picker to select the row (which you say you seem to have done but anyhow):

    - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
    

    OR you didn’t use the the following method to get the selected item from your picker

    - (NSInteger)selectedRowInComponent:(NSInteger)component
    

    This will get the selected row as Integer from your picker and do as you please with it.
    This should do the trick for yah. Good luck.

    Anyhow read the ref:
    https://developer.apple.com/documentation/uikit/uipickerview


    EDIT:

    An example of manually setting and getting of a selected row in a UIPickerView:

    the .h file:

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>
    {
        UIPickerView *picker;
        NSMutableArray *source;
    }
    
    @property (nonatomic,retain) UIPickerView *picker;
    @property (nonatomic,retain) NSMutableArray *source;
    
    -(void)pressed;
    
    @end
    

    the .m file:

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    @implementation ViewController
    
    @synthesize picker;
    @synthesize source;
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    
    - (void) viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        self.view.backgroundColor = [UIColor yellowColor];
    
        self.source = [[NSMutableArray alloc] initWithObjects:@"EU", @"USA", @"ASIA", nil];
    
        UIButton *pressme = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 280, 80)];
        [pressme setTitle:@"Press me!!!" forState:UIControlStateNormal];
        pressme.backgroundColor = [UIColor lightGrayColor];
        [pressme addTarget:self action:@selector(pressed) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:pressme];
    
        self.picker = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 110, 280, 300)];
        self.picker.delegate = self;
        self.picker.dataSource = self;
        [self.view addSubview:self.picker];
    
        //This is how you manually SET(!!) a selection!
        [self.picker selectRow:2 inComponent:0 animated:YES];
    }
    
    //logs the current selection of the picker manually
    -(void)pressed
    {
        //This is how you manually GET(!!) a selection
        int row = [self.picker selectedRowInComponent:0];
    
        NSLog(@"%@", [source objectAtIndex:row]);
    }
    
    - (NSInteger)numberOfComponentsInPickerView:
    (UIPickerView *)pickerView
    {
        return 1;
    }
    
    - (NSInteger)pickerView:(UIPickerView *)pickerView
    numberOfRowsInComponent:(NSInteger)component
    {
        return [source count];
    }
    
    - (NSString *)pickerView:(UIPickerView *)pickerView
                 titleForRow:(NSInteger)row
                forComponent:(NSInteger)component
    {
        return [source objectAtIndex:row];
    }
    
    #pragma mark -
    #pragma mark PickerView Delegate
    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
          inComponent:(NSInteger)component
    {
    //    NSLog(@"%@", [source objectAtIndex:row]);
    }
    
    @end
    

    EDIT for Swift solution (Source: Dan Beaulieu’s answer)

    Define an Outlet:

    @IBOutlet weak var pickerView: UIPickerView!  // for example
    

    Then in your viewWillAppear or your viewDidLoad, for example, you can use the following:

    pickerView.selectRow(rowMin, inComponent: 0, animated: true)
    pickerView.selectRow(rowSec, inComponent: 1, animated: true)
    

    If you inspect the Swift 2.0 framework you’ll see .selectRow defined as:

    func selectRow(row: Int, inComponent component: Int, animated: Bool) 
    

    option clicking .selectRow in Xcode displays the following:

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

Sidebar

Related Questions

I succesfully implemented a UIPickerView. However, I have a problem in selecting values. According
I have problem with show or hide form in Window Form Application. I start
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a small problem with an UIPickerView. It is part of a class
I have a little problem with my UIPickerView animation. I did set up the
Hi I am developing an iphone app where I have populated a uipickerview and
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with UIWebView delay when the load image from url. In my

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.