我有一个带3个按钮的视图,一个带有5个数组的pickerView和一些标签,这些标签为每个数组提供了基于答案的选择。除了以下(最终)位之外,一切都正常。
如果我选择按钮1(选择A系列阵列),我会在选择器中获得A系列数组,并在标签上找到相应的答案。然而,如果我选择另一个按钮,比如B系列,我会得到新的阵列,但标签仍然会响应A系列阵列。
我已经尝试过"如果"陈述," if else"陈述," if else case"语句"等等,但似乎没有任何作用。本质上想要A系列阵列的A系列答案,B系列阵列的B系列答案等。
因为一切都取决于选择一个替代阵列我认为错误在"否则如果"声明。有人可以让我了解我出错的地方 - 编程和iOS / xcode的新手。
.m文件(对不起长代码)
- (IBAction) aSeriesButton:(id) sender {
//select the A1 series picker
self.sizeStartArray = self.sizeASeriesArray;
[self.pickerASeries reloadAllComponents];
//temporarily fill labels for coding reference
self.sizeFormatPortrait.text = @"A Series Size";
self.sizeFormatLandscape.text =@"A Series Size";
self.sizeSameFormatUp.text = @"";
self.sizeSameFormatDown.text = @"";
self.sizeOtherFormatUp.text = @"";
self.sizeOtherFormatDown.text = @"";
}
- (IBAction) bSeriesButton:(id) sender {
//select the B1 series picker
self.sizeStartArray = self.sizeBSeriesArray;
[self.pickerBSeries reloadAllComponents];
//temporarily fill labels for coding reference
self.sizeFormatPortrait.text = @"B Series Size";
self.sizeFormatLandscape.text =@"B Series Size";
self.sizeSameFormatUp.text = @"";
self.sizeSameFormatDown.text = @"";
self.sizeOtherFormatUp.text = @"";
self.sizeOtherFormatDown.text = @"";
}
- (IBAction) canvasButton:(id) sender {
//select the Canvas series picker
self.sizeStartArray = self.sizeCanvasArray;
[self.pickerCanvas reloadAllComponents];
//temporarily fill labels for coding reference
self.sizeFormatPortrait.text = @"Canvas Series Size";
self.sizeFormatLandscape.text =@"Canvas Series Size";
self.sizeSameFormatUp.text = @"";
self.sizeSameFormatDown.text = @"";
self.sizeOtherFormatUp.text = @"";
self.sizeOtherFormatDown.text = @"";
}
- (IBAction) photoButton:(id) sender {
//select the Photo series picker
self.sizeStartArray = self.sizePhotoArray;
[self.pickerPhoto reloadAllComponents];
//temporarily fill labels for coding reference
self.sizeFormatPortrait.text = @"Photo Series Size";
self.sizeFormatLandscape.text =@"Photo Series Size";
self.sizeSameFormatUp.text = @"";
self.sizeSameFormatDown.text = @"";
self.sizeOtherFormatUp.text = @"";
self.sizeOtherFormatDown.text = @"";
}
- (IBAction) showStartPicker:(id)sender{
[pickerStart resignFirstResponder];
textFieldTouched = 0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
}
- (IBAction) showASeriesPicker:(id)sender{
[pickerASeries resignFirstResponder];
textFieldTouched = 1;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
}
- (IBAction)showBSeriesPicker:(id)sender{
[pickerBSeries resignFirstResponder];
textFieldTouched = 2;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
}
- (IBAction)showCanvasPicker:(id)sender{
[pickerCanvas resignFirstResponder];
textFieldTouched = 3;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
}
- (IBAction)showPhotoPicker:(id)sender{
[pickerPhoto resignFirstResponder];
textFieldTouched = 4;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
}
- (void)viewDidLoad {
[super viewDidLoad];
sizeStartArray = [[NSMutableArray alloc] init];
[sizeStartArray addObject:@"<- Pick a Format"];
self.sizeFormatPortrait.text = @"Select format";
self.sizeFormatLandscape.text = @"Select format";
self.sizeSameFormatUp.text = @"Select format";
self.sizeSameFormatDown.text = @"Select format";
self.sizeOtherFormatUp.text = @"Select format";
self.sizeOtherFormatDown.text = @"Select format";
sizeASeriesArray = [[NSMutableArray alloc] init];
[sizeASeriesArray addObject:@"A0"];
[sizeASeriesArray addObject:@"A1"];
[sizeASeriesArray addObject:@"A2"];
[sizeASeriesArray addObject:@"A3"];
[sizeASeriesArray addObject:@"A4"];
[sizeASeriesArray addObject:@"A5"];
sizeBSeriesArray = [[NSMutableArray alloc] init];
[sizeBSeriesArray addObject:@"B0"];
[sizeBSeriesArray addObject:@"B1"];
[sizeBSeriesArray addObject:@"B2"];
[sizeBSeriesArray addObject:@"B3"];
[sizeBSeriesArray addObject:@"B4"];
[sizeBSeriesArray addObject:@"B5"];
[sizeBSeriesArray addObject:@"B6"];
sizeCanvasArray = [[NSMutableArray alloc] init];
[sizeCanvasArray addObject:@"C0"];
[sizeCanvasArray addObject:@"C1"];
[sizeCanvasArray addObject:@"C2"];
[sizeCanvasArray addObject:@"C3"];
[sizeCanvasArray addObject:@"C4"];
[sizeCanvasArray addObject:@"C5"];
sizePhotoArray = [[NSMutableArray alloc] init];
[sizePhotoArray addObject:@"P0"];
[sizePhotoArray addObject:@"P1"];
[sizePhotoArray addObject:@"P2"];
[sizePhotoArray addObject:@"P3"];
[sizePhotoArray addObject:@"P4"];
[sizePhotoArray addObject:@"P5"];
[sizePhotoArray addObject:@"P6"];
[sizePhotoArray addObject:@"P7"];
[sizePhotoArray addObject:@"P8"];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
switch (textFieldTouched) {
case 0:
return [self.sizeStartArray count];
break;
case 1:
return [self.sizeASeriesArray count];
break;
case 2:
return [self.sizeBSeriesArray count];
break;
case 3:
return [self.sizeCanvasArray count];
break;
case 4:
return [self.sizePhotoArray count];
break;
default:
return 0;
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
switch (textFieldTouched) {
case 0:
return [self.sizeStartArray objectAtIndex:row];
break;
case 1:
return [self.sizeASeriesArray objectAtIndex:row];
break;
case 2:
return [self.sizeBSeriesArray objectAtIndex:row];
break;
case 3:
return [self.sizeCanvasArray objectAtIndex:row];
break;
case 4:
return [self.sizePhotoArray objectAtIndex:row];
break;
default:
return [self.sizeStartArray objectAtIndex:row];
}
}
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
switch (textFieldTouched) {
case 0:
textField_Start = [sizeStartArray objectAtIndex:[pickerView selectedRowInComponent:0]];
break;
case 1:
textField_ASeries = [sizeStartArray objectAtIndex:[pickerView selectedRowInComponent:0]];
break;
case 2:
textField_BSeries = [sizeStartArray objectAtIndex:[pickerView selectedRowInComponent:0]];
break;
case 3:
textField_Canvas = [sizeStartArray objectAtIndex:[pickerView selectedRowInComponent:0]];
break;
case 4:
textField_Photo = [sizeStartArray objectAtIndex:[pickerView selectedRowInComponent:0]];
break;
}
if ([pickerView isEqual: self.pickerASeries]) {
//let the data list for the A Series populate the labels - but how?
NSLog(@"Selected Row %d", row);
switch (row) {
case 0:
self.sizeFormatPortrait.text = @"A0 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"A0 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"No higher size...";
self.sizeSameFormatDown.text = @"A1 at 820mm X 597mm";
self.sizeOtherFormatUp.text = @"Higher Format";
self.sizeOtherFormatDown.text = @"Lower Format";
break;
case 1:
self.sizeFormatPortrait.text = @"A1 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"A1 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"A0...";
self.sizeSameFormatDown.text = @"A2...";
self.sizeOtherFormatUp.text = @"Higher Format";
self.sizeOtherFormatDown.text = @"Lower Format";
break;
case 2:
self.sizeFormatPortrait.text = @"A2 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"A2 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"A1...";
self.sizeSameFormatDown.text = @"A3...";
self.sizeOtherFormatUp.text = @"Higher Format";
self.sizeOtherFormatDown.text = @"Lower Format";
break;
case 3:
self.sizeFormatPortrait.text = @"A3 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"A3 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"A2...";
self.sizeSameFormatDown.text = @"A4...";
self.sizeOtherFormatUp.text = @"Higher Format";
self.sizeOtherFormatDown.text = @"Lower Format";
break;
case 4:
self.sizeFormatPortrait.text = @"A4 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"A4 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"A3...";
self.sizeSameFormatDown.text = @"A5...";
self.sizeOtherFormatUp.text = @"Higher Format";
self.sizeOtherFormatDown.text = @"Lower Format";
break;
case 5:
self.sizeFormatPortrait.text = @"A5 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"A5 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"A4...";
self.sizeSameFormatDown.text = @"A6 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
}
}
else if ([pickerView isEqual: self.pickerBSeries]) {
//let the data list for the B Series populate the labels - but how?
NSLog(@"Selected Row %d", row);
switch (row) {
case 0:
self.sizeFormatPortrait.text = @"B0 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"B0 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"No higher size...";
self.sizeSameFormatDown.text = @"B1 ...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 1:
self.sizeFormatPortrait.text = @"B1 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"B1 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"B0...";
self.sizeSameFormatDown.text = @"B2...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 2:
self.sizeFormatPortrait.text = @"B2 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"B2 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"B1...";
self.sizeSameFormatDown.text = @"B3...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 3:
self.sizeFormatPortrait.text = @"B3 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"B3 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"B2...";
self.sizeSameFormatDown.text = @"B4...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 4:
self.sizeFormatPortrait.text = @"B4 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"B4 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"B3...";
self.sizeSameFormatDown.text = @"B5...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 5:
self.sizeFormatPortrait.text = @"B5 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"B5 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"B4...";
self.sizeSameFormatDown.text = @"B6 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 6:
self.sizeFormatPortrait.text = @"B6 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"B6 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"B5...";
self.sizeSameFormatDown.text = @"B7 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
}
}
else if ([pickerView isEqual: self.pickerCanvas]) {
//let the data list for the Canvas Series populate the labels - but how?
NSLog(@"Selected Row %d", row);
switch (row) {
case 0:
self.sizeFormatPortrait.text = @"C0 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"C0 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"No higher size...";
self.sizeSameFormatDown.text = @"C1 ...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 1:
self.sizeFormatPortrait.text = @"C1 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"C1 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"C0...";
self.sizeSameFormatDown.text = @"C2...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 2:
self.sizeFormatPortrait.text = @"C2 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"C2 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"C1...";
self.sizeSameFormatDown.text = @"C3...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 3:
self.sizeFormatPortrait.text = @"C3 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"C3 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"C2...";
self.sizeSameFormatDown.text = @"C4...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 4:
self.sizeFormatPortrait.text = @"C4 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"C4 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"C3...";
self.sizeSameFormatDown.text = @"C5...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 5:
self.sizeFormatPortrait.text = @"C5 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"C5 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"C4...";
self.sizeSameFormatDown.text = @"C6 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
}
}
else if ([pickerView isEqual: self.pickerPhoto]) {
//let the data list for the Photo Series populate the labels - but how?
NSLog(@"Selected Row %d", row);
switch (row) {
case 0:
self.sizeFormatPortrait.text = @"P0 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P0 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"No higher size...";
self.sizeSameFormatDown.text = @"P1 ...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 1:
self.sizeFormatPortrait.text = @"P1 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P1 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P0...";
self.sizeSameFormatDown.text = @"P2...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 2:
self.sizeFormatPortrait.text = @"P2 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P2 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P1...";
self.sizeSameFormatDown.text = @"P3...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 3:
self.sizeFormatPortrait.text = @"P3 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P3 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P2...";
self.sizeSameFormatDown.text = @"P4...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 4:
self.sizeFormatPortrait.text = @"P4 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P4 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P3...";
self.sizeSameFormatDown.text = @"P5...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 5:
self.sizeFormatPortrait.text = @"P5 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P5 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P4...";
self.sizeSameFormatDown.text = @"P6 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 6:
self.sizeFormatPortrait.text = @"P6 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P6 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P5...";
self.sizeSameFormatDown.text = @"P7 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 7:
self.sizeFormatPortrait.text = @"P7 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P7 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P6...";
self.sizeSameFormatDown.text = @"P8 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
case 8:
self.sizeFormatPortrait.text = @"P8 Metric Size / Imperial Size";
self.sizeFormatLandscape.text = @"P8 Metric Size / Imperial Size";
self.sizeSameFormatUp.text = @"P7...";
self.sizeSameFormatDown.text = @"P9 and below...";
self.sizeOtherFormatUp.text = @"Higher Format...";
self.sizeOtherFormatDown.text = @"Lower Format...";
break;
}
}
}
@end
让我知道屏幕截图作为解释是否更有用 - 假设我可以将它们放入(或作为链接)