2009-09-08

How to add a pickerview to an iPhone application

@synthesize pickerView;
@synthesize tempView;
@synthesize statement;

// load the values to the array

- (void)viewDidLoad {
    arrayModels = [[NSMutableArray alloc] init];
    [arrayModels addObject:@"Pre War"];
    [arrayModels addObject:@"170 v"];
    [arrayModels addObject:@"170 s"];
    [arrayModels addObject:@"180"];
    [arrayModels addObject:@"190 SL"];
        [arrayModels addObject:@"220"];
        [arrayModels addObject:@"110"];
        [arrayModels addObject:@"111 Sedan"];
        [arrayModels addObject:@"111 Coupe"];
        [arrayModels addObject:@"113"];
        [arrayModels addObject:@"108 S"];
        [arrayModels addObject:@"114"];
        [arrayModels addObject:@"115 Sedan"];
        [arrayModels addObject:@"115 Coupe"];
        [arrayModels addObject:@"116"];
        [arrayModels addObject:@"123 Sedan"];
        [arrayModels addObject:@"123 Coupe"];
        [arrayModels addObject:@"123 Estate"];
        [arrayModels addObject:@"126"];
            [arrayModels addObject:@"124 Sedan"];
            [arrayModels addObject:@"124 Coupe"];
            [arrayModels addObject:@"124 Estate"];
            [arrayModels addObject:@"201"];
            [arrayModels addObject:@"202"];
            [arrayModels addObject:@"210"];
            [arrayModels addObject:@"140"];
            [arrayModels addObject:@"220"];
            [arrayModels addObject:@"203"];
            [arrayModels addObject:@"208 CLK"];
            [arrayModels addObject:@"170 SLK"];
            [arrayModels addObject:@"211"];
            [arrayModels addObject:@"163"];
            [arrayModels addObject:@"C Coupe"];
            [arrayModels addObject:@"CL"];
            [arrayModels addObject:@"230 SL"];
    [arrayModels addObject:@"168 A Class"];
    [arrayModels addObject:@"169 A Class"];
    [arrayModels addObject:@"209 CLK"];
    [arrayModels addObject:@"171 SLK"];
    [arrayModels addObject:@"245 B Class"];
    [arrayModels addObject:@"164 ML"];
    [arrayModels addObject:@"219"];
    [arrayModels addObject:@"221"];
    [arrayModels addObject:@"164 GL"];
    [arrayModels addObject:@"251 รข€“ R Class"];
    [arrayModels addObject:@"204"];
    [arrayModels addObject:@"129 SL"];
        tempView=[AddView alloc];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
    return 1;
}

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


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//[arrayModels objectAtIndex:row];
}

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

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

No comments: