Hello!
This seems like pretty standard code straight from the doc, so I'm not sure what I am doing wrong...
My 3-component picker doesn't look right when it loads, with the selection indicator being placed too low across the picker (so the grey bar is correctly placed, but the clear raised-looking overlay is too low).
Then, when I select a row, it all works perfectly unless I select the last row, in which case it thinks I selected the next-to-the-last row.
The count of titles in the array is correct (7, for instance), and when I select rows "0-5" it works great, but when I select row "6" (the 7th row), it still thinks I am selecting "5". So both the sixth and the seventh rows will return "5" instead of "5 and 6".
This happens for all of the three components, and actually is happening in a similar way in another one of my simpler pickers elsewhere in the code (actually, with that picker, only when I come from the parent view controller. When I come from the child view controller it is fine).
Can you help?
- (void)loadmypicker {
UIPickerView *mypicker = [[UIPickerView alloc] init];
[mypicker setDataSource:self];
[mypicker setDelegate:self];
pickerTitles_Dil = [[NSArray alloc] initWithObjects:@"0", @"1", @"2", @"3", @"4", @"5", @"6", nil];
pickerTitles_Eff = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", @"i", @"j", @"k", nil];
pickerTitles_Stat = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", nil];
[mypicker setShowsSelectionIndicator:YES];
[mypicker selectRow:0 inComponent:0 animated:NO];
[mypicker selectRow:0 inComponent:1 animated:NO];
[mypicker selectRow:0 inComponent:2 animated:NO];
[mypicker setFrame:CGRectMake(0, 98, 320, 253)];
[self addSubview:mypicker];
[mypicker release];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0)
return [pickerTitles_Dil objectAtIndex:row];
else if (component == 1)
return [pickerTitles_Eff objectAtIndex:row];
else return [pickerTitles_Stat objectAtIndex:row];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == 0)
{return [pickerTitles_Dil count];
}
else if (component == 1)
{return [pickerTitles_Eff count];
}
else
{return [pickerTitles_Stat count];
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog (@"row: %d, component :%d", row, component);
}
Thank you for your help!
Has anyone else had this problem? To summarize, the picker shows the last row but I cannot select it. Thanks!