I'm trying to learn how to use the UIPickerView, and I don't know why my alert view always prints the first element in the array (picker), vs anything else. I have a button press defined for the picker as:
- (IBAction)buttonPressed {
NSInteger row = [myPicker selectedRowInComponent:0];
NSString *s = [myPickerData objectAtIndex:row];
NSLog(@"%@", s);
NSString *title = [[NSString alloc] initWithFormat:@"You selected, %@", s];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:@"Message"
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alert show];
[alert release];
[title release];
}
my array defined as:
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *array = [[NSArray alloc] initWithObjects:@"0", @"1", @"2", nil];
self.myPickerData = array;
[array release];
}
I log the outputs when the picker is changed, and the values do get changed to 0, 1, 2, accordingly.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"%@", [myPickerData objectAtIndex:row]);
}
But the alert view never works. So I'm unsure what I am doing wrong here.