UIPickerviewのデリゲートメソッドを実装しているときに問題に直面しています。問題の説明は、ピッカービューに 3 つのコンポーネントがあり、各コンポーネントの行数が異なることです。このためのコードは次のとおりです。
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSInteger rows;
if (0 == component)
rows = 5;
else if (1 == component)
rows = 10;
else
rows = 15;
NSLog(@"Number of rows returned for component %d are rows %d",component, rows);
return rows;
}
これに続いて、次のような「titleForRow」デリゲート メソッド コードを実装しています。
#pragma -mark UIPIckerView Delegate Methods
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//NSString *temp;
//temp = [[NSString alloc] initWithString:[self.pocModelData.arrayOfDistricts objectAtIndex:row]];
if (0 == component)
{
NSLog(@"String returned is %@ for row %d for component %d", [self.pocModelData.arrayOfDistricts objectAtIndex:row], row, component);
return [self.pocModelData.arrayOfDistricts objectAtIndex:row];
}
else if
(1 == component){
NSLog(@"String returned is %@ for row %d for component %d", [self.pocModelData.arrayOfDistricts objectAtIndex:row], row, component);
return [self.pocModelData.arrayOfDistricts objectAtIndex:row];
}else{
NSLog(@"String returned is %@ for row %d for component %d", [self.pocModelData.arrayOfDistricts objectAtIndex:row], row, component);
return [self.pocModelData.arrayOfDistricts objectAtIndex:row];
}
//return temp;
// return [self.pocModelData.arrayOfDistricts objectAtIndex:row];
}
次のステートメントに示すように、実行時のこのメソッドは、コンポーネントごとに 3 行のみを返します。
2013-05-18 02:00:40.743 PopOverControllerExample[8228:c07] Number of rows returned for component 0 are rows 5
2013-05-18 02:00:41.221 PopOverControllerExample[8228:c07] Number of rows returned for component 1 are rows 10
2013-05-18 02:00:41.696 PopOverControllerExample[8228:c07] Number of rows returned for component 2 are rows 15
2013-05-18 02:00:42.035 PopOverControllerExample[8228:c07] Number of rows returned for component 0 are rows 5
2013-05-18 02:00:43.761 PopOverControllerExample[8228:c07] String returned is 1 for row 0 for component 0
2013-05-18 02:00:44.687 PopOverControllerExample[8228:c07] String returned is 2 for row 1 for component 0
2013-05-18 02:00:45.048 PopOverControllerExample[8228:c07] String returned is 3 for row 2 for component 0
2013-05-18 02:00:45.544 PopOverControllerExample[8228:c07] Number of rows returned for component 1 are rows 10
2013-05-18 02:00:46.131 PopOverControllerExample[8228:c07] String returned is 1 for row 0 for component 1
2013-05-18 02:00:46.620 PopOverControllerExample[8228:c07] String returned is 2 for row 1 for component 1
2013-05-18 02:00:47.380 PopOverControllerExample[8228:c07] String returned is 3 for row 2 for component 1
2013-05-18 02:00:47.772 PopOverControllerExample[8228:c07] Number of rows returned for component 2 are rows 15
2013-05-18 02:00:48.543 PopOverControllerExample[8228:c07] String returned is 1 for row 0 for component 2
2013-05-18 02:00:48.915 PopOverControllerExample[8228:c07] String returned is 2 for row 1 for component 2
2013-05-18 02:00:49.461 PopOverControllerExample[8228:c07] String returned is 3 for row 2 for component 2
コンポーネントごとに3回しか実行されない理由を理解できませんか? 行に一連のデータを入力しているため、データ ソースはすべての行に共通です。ここで何が問題なのですか。私は把握できず、しばらく立ち往生していますか? どんなガイダンスも高く評価され、事前に感謝します。