私が取り組んでいるコア データ ベースのアプリがあります。これは、EditingViewController を使用して、後でアプリ内に格納されるオブジェクトの属性を記述するユーザーからの入力を取得するさまざまな UI 要素を制御します。EditingViewController.xib ファイルには、datePicker、textField、numberSlider などの要素があり、私の問題は UIPickerView から来ており、.hidden = YES/NO;
式を使用して 1 つのビュー内ですべて制御されます。私の問題は、2 つの異なる NSMutableArray ソースを持つ必要がある 2 つの別々の画面に UIPickerView を設定する必要があることです。viewDidLoad メソッド内で、最初の NSMutableArray をセットアップします。
listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObject:@"Greenland"];
[listOfItems addObject:@"Switzerland"];
[listOfItems addObject:@"Norway"];
[listOfItems addObject:@"New Zealand"];
[listOfItems addObject:@"Greece"];
[listOfItems addObject:@"Rome"];
[listOfItems addObject:@"Ireland"];
その後、UIPickerView *picker に次のコードを入力します。
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)picker;
{
return 1;
}
- (void)pickerView:(UIPickerView *)picker didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
label.text= [listOfItems objectAtIndex:row];// The label is simply setup to show where the picker selector is at
}
- (NSInteger)pickerView:(UIPickerView *)picker numberOfRowsInComponent:(NSInteger)component;
{
return 8;//[listOfItems count];
}
- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent: (NSInteger)component;
{
return [listOfItems objectAtIndex:row];
}
そして、それは最初の属性と配列に対してうまく機能します。その後、別の uitableviewcell が選択されると、ピッカーが非表示picker.hidden = YES;
になり、別のピッカー picker2 が別の情報の配列と共に表示される必要があります。しかし、プロセスを複製しようとすると、まったく新しいピッカーを設定し、それを picker2 と呼び、最初のピッカーのすぐ隣に作成した別の NSMutableArray を入力しようとします (これもすべて、私の EditingViewController ではすべての一部であるためです)。同じビューの、ビューに応じて異なる UI 要素を呼び出すだけです) picker2 に新しい配列を入力できません。2 つの異なるアレイを設定できるように設定する方法がわかりません。2 つのピッカー ビューが必要ですか? 1本だけで出来ますか?の適切な構文は何ですか- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent: (NSInteger)component;
2 つの配列を別々に表示できるようにする方法は? 誰かがこれについて私を助けてくれることを願っています、事前に感謝します!