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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:58:53+00:00 2026-06-07T09:58:53+00:00

I’m trying to get a UIPickerView to display when a UITextField is clicked on

  • 0

I’m trying to get a UIPickerView to display when a UITextField is clicked on by the user. I also want the UIPickerView to have a toolbar at the top with buttons to submit the selection and cancel.

Do I need to connect a UIPickerView in the interface builder, or connect an action somewhere else? I am also getting warnings when I build. One warning is under the resignFirstResponder. It says:

local declaration of age hides instance variable

There are several more warning similar to the one above for different variables.

Another warning is:

Class ‘PracticePickerViewController’ does not implement the ‘UIActionsheetDelegate’ protocol.

Here are my .h and .m files:

.h

#import <UIKit/UIKit.h>

@interface PracticePickerViewController : UIViewController <UITextFieldDelegate>{

    IBOutlet UITextField *age;
    IBOutlet UIPickerView *agePickerView;
    IBOutlet UIActionSheet *actionSheet;
    IBOutlet UIToolbar *pickerToolbar;

}


@end

.m

#import "PracticePickerViewController.h"

@implementation PracticePickerViewController

-(void)textFieldDidBeginEditing:(UITextField *)age{
    [age resignFirstResponder];

    actionSheet = [[UIActionSheet alloc] initWithTitle:@"Pick Your Age" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    CGRect pickerFrame = CGRectMake(0,40,0,0);

    UIPickerView *agePickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
    agePickerView.showsSelectionIndicator = YES;
    agePickerView.dataSource = self;
    agePickerView.delegate = self;
    [actionSheet addSubview:agePickerView];

    pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
    pickerToolbar.barStyle = UIBarStyleBlackOpaque;
    [pickerToolbar sizeToFit];

    NSMutableArray *barItems = [[NSMutableArray alloc] init];

    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];

    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
    [barItems addObject:doneBtn];

    UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
    [barItems addObject:cancelBtn];

    [pickerToolbar setItems:barItems animated:YES];

    [actionSheet addSubview:pickerToolbar];
    [actionSheet addSubview:agePickerView];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0,0,320,485)];

}
  • 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-07T09:58:56+00:00Added an answer on June 7, 2026 at 9:58 am

    local declaration of age hides instance variable

    This means you’ve defined a variable name that is already used by a class variable (so in this case, you may have declared UITextField *age somewhere in the class, but you can’t re-use variable name age in this class because the compiler will confuse it with the class variable).

    Class ‘PracticePickerViewController’ does not implement the ‘UIActionsheetDelegate’ protocol.

    You haven’t made your PracticePickerViewController a UIActionsheetDelegate. To do this, you have change your interface header (PracticePickerViewController.h) to read:

    @interface PracticePickerViewController : UIViewController <UITextFieldDelegate, UIActionsheetDelegate>{
    

    Don’t forget to implement the required delegate methods as well!

    Finally, I strongly recommend you check out the ActionSheetPicker project.
    It’s a drop-in class that has exactly the functionality you’re trying to implement, so you can either replace your current code with that, or just use it as a reference to see how to implement the embedded ActionSheet inside the UIPickerView correctly. Hope all that helps!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
i want to parse a xhtml file and display in UITableView. what is the
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.