Skip navigation

UIPicker question

2403 Views 5 Replies Latest reply: Jan 25, 2011 8:53 PM by RayNewbie RSS
mac seeker Calculating status...
Currently Being Moderated
Jan 22, 2011 7:42 PM
Hello, so I am fairly new to the whole programming scene and I have a question regarding my UIPickerView.

My goal is I want a picker that has 2 columns, each of which display 38 items in it, both the same items. And I want them to each output something different with each combination. For example, the 1st in column 1 plus the 1st in column 2 is outputing different then the 1st in column 1 plus the 10th in column 2.

I have gotten as far as being able to display both columns with the 38 different labels, but I dont know how to have them interact seperately with each other.

I hope this makes sense to somebody, its hard for me to describe what exactly I want since Im so new.

Thanks very much, any help is appreciated!!
2.8 Ghz Quad Core, Mac OS X (10.6.5)
  • RayNewbie Level 5 Level 5 (6,810 points)
    Currently Being Moderated
    Jan 23, 2011 4:59 AM (in response to mac seeker)
    Hi Seeker, and welcome to the Dev Forum!
    mac seeker wrote:
    I have gotten as far as being able to display both columns with the 38 different labels, but I dont know how to have them interact seperately with each other.

    The columns (called "components" in the doc) are already separate, you just need to use the [selectedRowInComponent:|http://developer.apple.com/library/ios/documentation/U IKit/Reference/UIPickerViewClass/Reference/UIPickerView.html#//appleref/doc/uid/TP40006842-CH3-SW7] method to obtain the currently selected rows. Your controller code might look something like this:

    // SeekerPickerViewController.h
    @interface SeekerPickerViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
    UIPickerView *myPickerView;
    NSArray *myPickerData;
    }
    @property (nonatomic, retain) IBOutlet UIPickerView *myPickerView;
    @property (nonatomic, retain) NSArray *myPickerData;
    - (void)processSelection;
    @end

    // SeekerPickerViewController.m
    #import "SeekerPickerViewController.h"

    @implementation SeekerPickerViewController
    @synthesize myPickerView, myPickerData;

    - (void)processSelection {
    NSInteger index0 = [myPickerView selectedRowInComponent:0];
    NSInteger index1 = [myPickerView selectedRowInComponent:1];
    NSLog(@"Current selections: %@, %@", [myPickerData objectAtIndex:index0], [myPickerData objectAtIndex:index1]);
    }

    - (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *data = [[NSArray alloc] initWithObjects:@"First", @"Second", @"Third", nil];
    self.myPickerData = data;
    [data release];
    // NSLog(@"myPickerData=%@", myPickerData);
    [self processSelection];
    }


    - (void)dealloc {
    [myPickerData release];
    [myPickerView release];
    [super dealloc];
    }

    #pragma mark -
    #pragma mark Picker View Data Source Methods
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 2;
    }

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

    #pragma mark -
    #pragma mark Picker View Delegate Methods
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [myPickerData objectAtIndex:row];
    }

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    NSLog(@"Row %d in Component %d has been selected", row, component);
    [self processSelection];
    }
    @end

    - Ray
    iMac, Mac OS X (10.5.8)
  • RayNewbie Level 5 Level 5 (6,810 points)
    Currently Being Moderated
    Jan 23, 2011 6:42 PM (in response to mac seeker)
    You're very welcome, Tim. Those #pragma lines are just to help organize the file. For example, open SeekerPickerViewController.m in a Xcode text editor window and click on the +*Function menu*+ in the middle of the +*Navigation Bar*+ (see [Figure 4-2 Text editor navigation bar|http://developer.apple.com/library/ios/documentation/DeveloperTools/Concept ual/XcodeWorkspace/100-TheText_Editor/text_editor.html#//appleref/doc/uid/TP40002679-SW3] in the Xcode Workspace Guide). The Function menu labels were produced by the #pragma lines. But those #pragmas have no effect on the actual code, so just remove them if they're distracting.

    When you have a moment btw, here's the info on how to close your thread whenever you feel it's resolved: [http://discussions.apple.com/help.jspa#answers]. - Ray
    iMac, Mac OS X (10.5.8)
  • RayNewbie Level 5 Level 5 (6,810 points)
    Currently Being Moderated
    Jan 25, 2011 8:53 PM (in response to mac seeker)
    mac seeker wrote:
    Is there anything you recommend, such as books or online tutorials to help me with all this?

    Try +Beginning iPhone 3 Development: Exploring the iPhone SDK+ by David Mark and Jeff LaMarche.
    \- Ray
    iMac, Mac OS X (10.5.8)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.