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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:33:05+00:00 2026-05-30T02:33:05+00:00

I have Xcode 4.2 and I am trying to create a drop down menu.

  • 0

I have Xcode 4.2 and I am trying to create a drop down menu. I would like the drop down menu to drop down with words or numbers. Then when I select something from the list I would like it to appear in a table on a different page. My question is: how would I write this?
Thanks

  • 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-30T02:33:06+00:00Added an answer on May 30, 2026 at 2:33 am

    First create a UIViewController subclass with a nib file by going File > New > New File and following the prompts.

    Select UIViewController subclass

    Name your class

    Now open the nib (MyViewController.xib).

    MyViewController.xib

    You should drag a UIPickerView and a UITableView into the view and arrange them however you like (it doesn’t matter).

    UITableView

    UIPickerView

    Arrange the interface elements

    Next open the header file (MyViewController.h) for your UIViewController subclass.

    MyViewController.h

    At the end of the

    @interface MyViewController : UIViewController {
    

    line add <UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource> so it looks like this

    @interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource>
    

    Next you will need to add references to your tableview and picker and also two arrays of values. Just above @end add the following lines

    @property (strong, nonatomic) IBOutlet UITableView* tableView;
    @property (strong, nonatomic) IBOutlet UIPickerView* pickerView;
    @property (strong, nonatomic) NSMutableArray* tableData;
    @property (strong, nonatomic) NSMutableArray* pickerData;
    

    MyViewController.h should look like this

    Then just go back to your nib file and connect the UITableView and UIPickerView to these variables.

    Connect your components

    Now in your source file (MyViewController.m) you need to synthesize you references. So add @synthesize tableView, pickerView, tableData, pickerData to the file just below @implementation MyViewController

    MyViewController.m

    Now to add the delegate methods, there will be quite a few of them, but they’re pretty self explanatory.

    The delegate methods for the UITableView are

    - (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView;
    
    - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;
    
    - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
    
    - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
    

    The delegate methods for the UIPickerView are

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
    
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
    
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
    
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
    

    They should be added to the source file and used as follows

    UITableView:

    - (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
        // The number of sections in the UITableView
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
        // The number of rows in the UITableView
        return [tableData count];
    }
    
    - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
    
        // Set the table cell text to the appropriate value in tableData
        cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    
        return cell;
    }
    
    - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // Whatever happens when you select a table view row.
    }
    

    UIPickerView:

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
    {
        // The number of sections in the UIPickerView
        return 1;
    }
    
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
    {
        // The number of rows in the UIPickerView
        return [pickerData count];
    }
    
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
    {
        // The data for each row in the UIPickerView
        return [pickerData objectAtIndex:row];
    }
    
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        // whatever you want to happen when a row is selected.
    
        // here I am assuming you want to remove from the picker and add to the table on selection
        [tableData addObject:[pickerData objectAtIndex:row]];
        [pickerData removeObjectAtIndex:row];
    
        [tableView reloadData];
        [pickerView reloadAllComponents];
    }
    

    MyViewController should have these methods.

    Ok, the final thing you have to do is set the delegates and initialise the data. In the - (void)viewDidLoad method of MyViewController add the following lines

    tableView.delegate = self;
    tableView.dataSource = self;
    pickerView.delegate = self;
    pickerView.dataSource = self;
    
    tableData = [[NSMutableArray alloc] init]; // table starts empty
    pickerData = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", nil]; // picker starts with values 1, 2, 3, 4, 5
    
    [tableView reloadData];
    [pickerView reloadAllComponents];
    

    - (void)viewDidLoad should look like this.

    There are a few more delegate methods which you can find in the spec for the classes but these ones should be adequate for now.

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

Sidebar

Related Questions

I have a XCode which builds and runs under XCode. I would like to
I'm trying to create a news viewer with Xcode 4. This should look like
I am trying to create a simple modal dialog in XCode 4. I have
Xcode 4.2 iPhone Project I am trying to create a tableView that's populated from
I have 2 errors in XCode and am trying to figure out what they
I have a plist file in my resources group in xcode. I am trying
I have started a project from an XCode template I have created. When I
I'm trying to create a Java Tool by using Xcode. I've already changed my
Im trying to create a spinning square inside of xcode using opengl but instead
I am trying to create a simple translation program for iPhone and have drawn

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.