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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:05:14+00:00 2026-05-25T06:05:14+00:00

Bah. I’ve pulled my hair out over this problem for the past couple days

  • 0

Bah. I’ve pulled my hair out over this problem for the past couple days now, but I know I must be overlooking the obvious. I’ve made my PickerViewController(.h./m) and PickerViewAppDelegate(.h/.m) files and they run fine as a standalone program, but I would like to have the picker pop up after a procedureal event occurs in my “helloworld.m” file. I can get the picker to show up, but I cannot for the life of me figure out how to populate it so that it isn’t blank. I THINK I’ve done everything right up until I try to pass my array to my pickerview object. What am I doing wrong?

PickerViewController.h

#import <UIKit/UIKit.h>

@interface PickerViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {

    IBOutlet UIPickerView *pickerView;
    NSMutableArray *scrollerData;
}
@property (nonatomic, retain) IBOutlet UIPickerView *pickerView;
@property (nonatomic, retain) NSMutableArray *scrollerData;

-(void)setScrollerData:(NSMutableArray *)array;
@end

PickerViewController.m

#import "PickerViewController.h"


@implementation PickerViewController
@synthesize pickerView, scrollerData;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
//  [arrayColors release];
    [super dealloc];
}

-(void)setScrollerData:(NSMutableArray *)array
{
    //[self.scrollerData arrayByAddingObjectsFromArray:array];
    scrollerData = array;
}

#pragma mark -
#pragma mark Picker View Methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {

    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {

    return [scrollerData count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

    return [scrollerData objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    NSLog(@"Selected Number: %@. Index of selected numbers: %i", [scrollerData objectAtIndex:row], row);
}

PickerViewAppDelegate.h

#import <UIKit/UIKit.h>

@class PickerViewController;

@interface PickerViewAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    PickerViewController *pvController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

PickerViewAppDelegate.m

#import "PickerViewAppDelegate.h"
#import "PickerViewController.h"

@implementation PickerViewAppDelegate

@synthesize window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    pvController = [[PickerViewController alloc] initWithNibName:@"PickerView" bundle:[NSBundle mainBundle]];

    [window addSubview:pvController.view];

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [pvController release];
    [window release];
    [super dealloc];
}


@end

Helloworld.m

...
        UIView* view = [[CCDirector sharedDirector] openGLView];

        UIPickerView *pickerView=[[UIPickerView alloc] init];
        pickerView.frame=CGRectMake(100,100, 200, 200);



        NSMutableArray *arrayNumbers = [[NSMutableArray alloc] init];
        [arrayNumbers addObject:@"30"];
        [arrayNumbers addObject:@"31"];
        [arrayNumbers addObject:@"32"];
        [arrayNumbers addObject:@"33"];
        [arrayNumbers addObject:@"34"];
        [arrayNumbers addObject:@"35"];
        [arrayNumbers addObject:@"36"];

        [pickerView setscrollerData: arrayNumbers];//Should I be calling pickerView here or something else?


        [view addSubview: pickerView];
        pickerView.hidden=NO;
...
  • 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-25T06:05:15+00:00Added an answer on May 25, 2026 at 6:05 am

    You have overridden the setter method generated by @synthesize in PickerViewController, so you are no longer retaining it.

    Then, you are calling setScrollerData on your pickerView (this should be giving you a warning or crashing since pickerView doesn’t respond to that method).

    You are not setting PickerViewController as the delegate or datasource of your picker view in helloworld.m.

    I can’t see where your hello world code fits in. It seems to be adding a new picker view rather than using the one from the xib of PickerViewController. You should be instantiating pickerviewcontroller from your hello world and adding its .view as a subview or presenting it as a modal view controller rather than setting up a new picker view. You can then pass your array to the instance of pickerviewcontroller. Note though that it is not standard to have a separate view controller for what is essentially a subview, though I don’t have much knowledge of cocos2d so I don’t know if this is normal when using that framework.

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

Sidebar

Related Questions

Bah, vbscript. I'm trying to figure out how to get this statement to work:
I have a folder structure like this: /some_folder /tmp /tmp/foo /tmp/foo/fu * /tmp/bar /tmp/bar/bah
I've built a widget for OS X. It's written in Flash (bah, I know)
I've been developing in Java using maven for a few days now. Today I
Bah, I've been fiddling on how to do this. I need a function that
Bah! I have recently installed the MiniProfiler from http://code.google.com/p/mvc-mini-profiler/ attempting to find all the
I have this xml snippet as part of a xml file that will be
Python's setdefault allows you to get a value from a dictionary, but if the
Okay so I'm struggling more than I should with this. I've been to the
I have a string like s = title='bah' name='john and jill' purple='haze' none=None i=1

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.