這似乎是直接從文檔非常標準的代碼,所以我不知道我做錯了......選擇器不能識別的最後一排
我的三分量選擇器看起來不正確時它加載時,選擇指示器在拾取器上放置得太低(所以灰色條被正確放置,但明顯的凸起的覆蓋層太低)。
然後,當我選擇一行時,除非選擇最後一行,否則它會完美地工作,在這種情況下,它認爲我選擇了倒數第二行。
數組中的標題數是正確的(例如7),當我選擇行「0-5」時,它的效果很好,但是當我選擇第6行(第7行)時,它仍然我認爲我選擇了「5」。因此,第六行和第七行將返回「5」而不是「5和6」。
這發生在所有這三個組件上,並且實際上是以類似的方式發生在代碼中其他地方的另一個更簡單的採集器中(實際上,只有當我來自父視圖控制器時,才使用該採集器。我來自子視圖控制器它沒事)。
你能幫忙嗎?
- (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);
}
謝謝你的幫忙!
有沒有其他人有這個問題?總之,選取器顯示最後一行,但我不能選擇它。謝謝!
我可以建議你重新標記以包含語言/應用程序/ ???這是指 – Basic 2010-09-30 16:36:48
當然......這有幫助嗎?謝謝! – snorkelt 2010-09-30 18:32:07