初めての iOS アプリを開発していますが、行き詰まっています。たくさん検索しましたが、解決策が見つかりませんでした。
2 つのコンポーネント (5 つの配列オブジェクトを持つ Picker1 と 2 を持つ Picker2) を持つ UIPickerView と UIImageView があり、2 つのピッカーで選択されたデータに従って別の画像を設定する必要があります。
元:
Picker1 - A and Picker2 - A | Image - AA
Picker1 - B and Picker2 - A | Image - BA
Picker1 - A and Picker2 - B | Image - AB
Picker1 - B and Picker2 - B | Image - BB
...
これが私のコードです:
#define MOVEIS 0
#define CORES 1
- (void)viewDidLoad
{
[super viewDidLoad];
ContainerPickerView.frame = CGRectMake(0, 390, 320, 207);
ContainerPickerView.backgroundColor = [UIColor whiteColor];
CatalogoPicker.showsSelectionIndicator = TRUE;
self.CoresMoveis=[[NSArray alloc] initWithObjects:@"Preto",@"Vermelho",@"Castanho",@"Cinzento",@"Branco", nil];
self.CoresChao=[[NSArray alloc] initWithObjects:@"Escuro", @"Claro", nil];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == MOVEIS) {
return [CoresMoveis count];
}
if (component == CORES) {
return [CoresChao count];
}
return 0;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component == MOVEIS) {
return [CoresMoveis objectAtIndex:row];
}
if (component == CORES) {
return [CoresChao objectAtIndex:row];
}
return 0;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Preto"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Escuro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_preto_chao_escuro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Vermelho"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Escuro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_vermelho_chao_escuro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Castanho"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Escuro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_castanho_chao_escuro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Cinzento"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Escuro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_cinzento_chao_escuro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Branco"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Escuro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_branco_chao_escuro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Vermelho"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Claro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_vermelho_chao_claro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Castanho"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Claro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_castanho_chao_claro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Cinzento"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Claro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_cinzento_chao_claro.jpg"];
}
else if ([[CoresMoveis objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"Branco"] || [[CoresChao objectAtIndex:[pickerView selectedRowInComponent:1]] isEqual: @"Claro"]) {
_ImageView_Catalogo.image = [UIImage imageNamed:@"movel_branco_chao_claro.jpg"];
}
}