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

  • Home
  • SEARCH
  • 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 5983591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:15:11+00:00 2026-05-22T22:15:11+00:00

another Objective-C one for you, probably pretty obvious but I have been at this

  • 0

another Objective-C one for you, probably pretty obvious but I have been at this for a few days now, and can’t get it to work after trawling through similar problems on here and elsewhere!

Pretty much I have a 5 segment picker which, when a button is clicked, an alert sheet is shown which once accepted grabs the values of the picker wheels. Easy huh, yet I cant get it to work and I’m not sure where I’m going wrong… Some code below… it’s probably pretty bad… but it’s all pretty new to me so any help would be appreciated. All this is done without using InterfaceBuilder by the way.

Everything up to the loop after the action sheet works fine… I just can’t get the values out!

(ps, i hope the formatting works! And I have changed some of my namings and that but all should be right)

Thanks!

MyFile.h

@interface MyViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource, UIActionSheetDelegate>
{
    UIPickerView * thePickerView;
    NSArray *thePickerValues;
}
@property (nonatomic, retain) UIPickerView *thePickerView;
@property (nonatomic, retain) NSArray *thePickerValues;

- (void)buildPicker;
- (void)doAction;

@end

MyFile.m

@implementation MyViewController
@synthesize thePickerView;
@synthesize thePickerValues;

- (void)viewDidLoad
{
    NSArray *values = [[NSArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil];
    thePickerValues = values;
    [values release];
    [self buildPicker];
}

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

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

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [self.thePickerValues objectAtIndex:row];
}

-(void)buildPicker
{
    CGRect pickerFrame = CGRectMake(0.0f,130.0f,320.0,100.0f);
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
    pickerView.delegate = self;
    pickerView.showsSelectionIndicator = YES;
    [self.view addSubview:pickerView];
    [pickerView release];
}



- (void)doAction
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:[NSString stringWithFormat:@"Blah blah"]
                                  delegate:self
                                  cancelButtonTitle:@"No!"
                                  destructiveButtonTitle:@"Yes!"
                                  otherButtonTitles:nil];
    [actionSheet showInView:self.parentViewController.tabBarController.view];
    [actionSheet release];
}

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(!(buttonIndex == [actionSheet cancelButtonIndex]))
    {
        NSLog(@"Get the picker values");
        for(int i = 0; i<5;i++)
        {
            NSInteger *selectedValue = [thePickerView selectedRowInComponent:i];
            NSLog(@"Wheel : %i Value : %i", i, selectedValue);
            [selectedValue release];
        }
    }
}
  • 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-22T22:15:11+00:00Added an answer on May 22, 2026 at 10:15 pm

    An alternative answer: thePickerView is nil. I don’t see you assigning a value to it, right?

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

Sidebar

Related Questions

I've been programming objective-C for a few months now and have done pretty well
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;
This is probably a common Objective-C question reported by Java coders, but I don't
Can a Objective c interface have more than one implementation? Example I could have
another request sorry.. Right now I am reading the tokens in one by one
One book for about iPhone programming instantiates classes like this: [[Class alloc] init] Another
Objective-C uses a sophisticated message-passing system when one object calls a method on another
My objective is to simply to change a function call from one to another,
My objective is to write a program which will call another executable on a
Another basic Rails question: I have a database table that needs to contain references

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.