プログラムでビューを作成するコードを作成しています。このビューでは、2つのUIPickerViewを作成していますが、タイトルが説明するように、データをリストに取り込むと、すべてのデータが2番目のテーブルに入り、最初のテーブルには入りません。どこに問題があるのかは分かりますが、問題を解決する方法はわかりません。ここでは、関連していない部分を編集するコードを示します。プログラムで2つのUIPickerViewを作成しますが、すべての値は2番目に移動します
以下のセクションでは、ピッカービューを作成します。基本的に私は大きなデータリストを持っています。私が "RadioButton"の出現を見ると、私はPickerViewを作成します。 RadioButtonは複数回出現することがあり、私の問題がどこにあるのでしょうか。
for(int i = 0; i < [list count]; i++){
...
else if([input.controlTypeName compare:@"RadioButton"] == NSOrderedSame){
[radioList addObject:input.sourceText];
radioPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(50, y, 220, 200)];
radioPicker.delegate = self;
radioPicker.showsSelectionIndicator = YES;
[inputsView addSubview:radioPicker];
y = y+220;
}
基本的に何が起こっているようだ
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
// Handle the selection
}
// tell the picker how many rows are available for a given component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if([pickerView isEqual: radioPicker]){
return [radioList count];
}
// tell the picker how many components it will have
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
// tell the picker the title for a given component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if([pickerView isEqual: radioPicker]){
id myArrayElement = [radioList objectAtIndex:row];
NSString *title = myArrayElement;
NSLog(@"title to fill radio:%@", title);
return title;
}
}
// tell the picker the width of each row for a given component
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
int sectionWidth = 200;
return sectionWidth;
}
次のような方法があるデリゲートが..「のRadioButton」ListPickerの第二創出にある
は、最初の作成は失うタグ「radioPicker」と線
if([pickerView isEqual: radioPicker]){
が失敗します。したがって、すべてのデータが2番目(および最新)の作成にプッシュされます。しかし、私はこれが起こらないようにする方法を知らない。どんなアイデアも素晴らしいだろう。
ありがとうございました。
この場合はisEqualではなく==を使用しますが、ivarとのポインタの等価性をチェックしたいとします。 2番目のピッカービューを作成する場所にコードが表示されません。 – jrturton
データの配列に 'radiobutton'の2番目のインスタンスが見つかると、2番目のピッカービューが作成されます。私は引用した場合と全く同じelseを使用します。 –