ラベルの複数コンポーネント ピッカービューで最近選択された値を表示する必要があります
- 3 つの NSMutableArrays (rowOneItems、rowTwoItems、rowThreeItems) によって設定された 3 つのコンポーネントを持つ pickerView があります。
- また、変更されたコンポーネントからユーザーが最後に選択したものを正しく表示している NSLog ステートメントもあります。
- ただし、最近選択した値をラベルに正しく表示する方法がわかりません。
現在、ラベルは最初のピッカーから値を取得して表示しますが、2 番目と 3 番目の値を適切に更新しません。むしろ、それと同じ場所にある値を選択します。たとえば、3 つの配列すべてに鳥、犬、猫の値が含まれている場合、ピッカー ビューで「犬」を選択すると、ラベルに 3 つの「犬」の値が表示されます。
私がやりたいことは、ユーザーがピッカービューで選択した値をラベルに表示することです。
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
//log which row is selected in each component
//this shows the values correctly in output
if(component ==1) {
return NSLog(@"Selected Difficulty: %@",[rowTwoItems objectAtIndex:row]);
}
else if(component ==2) {
return NSLog(@"Selected Duration: %@",[rowThreeItems objectAtIndex:row]);
}
else{
NSLog(@"Selected Type: %@",[rowOneItems objectAtIndex:row]);
}
//define chosen items
//stuck here. tried using a if else statement as above, but of course that would only return the first value in the label
NSString *chosenType = [rowOneItems objectAtIndex:row];
NSString *chosenDifficulty = [rowTwoItems objectAtIndex:row];
NSString *chosenDuration = [rowThreeItems objectAtIndex:row];
[workoutResults setText:[NSString stringWithFormat:@"%@, %@, %@", chosenType, chosenDifficulty, chosenDuration]];
}
obj-c の学習を始めたばかりなので、これがまったくの初心者の質問である場合は申し訳ありません。ご指導いただきありがとうございます。