Okay, I want the user to be able to tap on textbox/dropdown menu (as in the link) and select some predefined values from the picker. I'm not sure how to go about call the PickerViewController when the users taps on the textbox ?
I have the following code in place:
PickerViewController.h
Code:
@interface PickerViewController : UIViewController {
IBOutlet UIPickerView *pickerView;
NSMutableArray *list;
}
@end
PickerViewController.m
Code:
#import "PickerViewController.h"
@implementation PickerViewController
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger) forComponent:(NSInteger) component{
return[list count];
}
-(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return[list objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog(@"Selected item: %@ index of selected item: %i",[list objectAtIndex:row], row);
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
list = [[NSMutableArray alloc] init];
[list addObject:@"red"];
[list addObject:@"blue"];
[list addObject:@"yellow"];
[list addObject:@"pink"];
}
- (void)dealloc {
[list release];
[super dealloc];
}
@end