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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:18:47+00:00 2026-06-05T15:18:47+00:00

I have been having trouble pulling up a custom UIPickerView from the textfield’s inputview

  • 0

I have been having trouble pulling up a custom UIPickerView from the textfield’s inputview property. I have been working on this for awhile, did some research, and tried to put together a separate project based on Apple’s UICatalog example.

However, whenever I tap inside the textfield all I get is a black screen that pops up in place of the picker view. Im sure I’ve overlooked something but I have been looking for days any help would be appreciated.

Keep in mind this was my test project to see if I could add this functionality to my other app and that a lot of the code I tried to copy from the UICatalog app. Sorry if anything doesn’t make sense and please feel free to ask any questions you may have. Thank you.

//  ViewController.h
//  TestPicker

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>{

UIPickerView *picker;
     //The picker view the textfield responds to.

IBOutlet UITextField *myText;
     //The textfield which has the input view of a picker.

NSArray *testArray;
     //The array which values are loaded into the picker.
}

@end


//  ViewController.m
//  TestPicker


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    picker.delegate=self;
    picker.dataSource=self;
    myText.delegate=self;

    [self createPicker];

    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } 
    else {
        return YES;
    }
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
    myText.inputView=picker;
    return YES;
}

-(void)textFieldDidBeginEditing:(UITextField *)textField{

}


- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSString *returnStr = @"";

    if (pickerView == picker)
    {
        if (component == 0)
        {
            returnStr = [testArray objectAtIndex:row];
        }
        else
        {
            returnStr = [[NSNumber numberWithInt:row] stringValue];
        }
    }

    return returnStr;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [testArray count];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}


- (void)createPicker
{
    testArray = [NSArray arrayWithObjects:
                            @"John Appleseed", @"Chris Armstrong", @"Serena Auroux",
                            @"Susan Bean", @"Luis Becerra", @"Kate Bell", @"Alain Briere",
                        nil];


    picker = [[UIPickerView alloc] initWithFrame:CGRectZero];


    picker.showsSelectionIndicator = YES;   // note this is default to NO

    picker.delegate = self;
    picker.dataSource = self;

}

@end
  • 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-05T15:18:48+00:00Added an answer on June 5, 2026 at 3:18 pm

    The problem is in this method:

    -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
        picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
        myText.inputView=picker;
        return YES;
    }
    

    You already created picker in your createPicker method, called from viewDidLoad, so this creates another instance (this instance won’t have the delegate or data source set to self, since these were set on the first instance you created). If you just delete the first line of this method, it should work.

    Two other comments on your code. The first 2 lines in the viewDidLoad method aren’t doing anything since you haven’t created picker yet — they should be deleted. You also need to implement the pickerView:didSelectRow:inComponent: method in order to get the selected value of your picker into the text field.

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

Sidebar

Related Questions

Hello I have been having trouble with this for a while now. I have
I am having trouble writing a query. I have been working with UNION on
No doubt elements of this question have been asked before, but I'm having trouble
I've been working on a small blog form but have been having trouble with
I have been having trouble getting this plugin to attach correctly to ajax loaded
I have been having trouble deploying liferay portlets and themes from the command line
I have been having trouble while attempting to use the nextLine() method from java.util.Scanner.
so I have been having trouble with grabbing information from a device that is
i have been having this trouble when trying to obtain json data. lets say
I have been having some real trouble with this for a while. I am

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.