Обратите внимание, что вы можете заменить весь код:
if ([[array1 objectAtIndex:row] isEqual:@"1"]) {
if ([[array2 objectAtIndex:row] isEqual:@"A"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_1A.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"B"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_1B.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"C"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_1C.pdf"]]]]; }
}
if ([[array1 objectAtIndex:row] isEqual:@"2"]) {
if ([[array2 objectAtIndex:row] isEqual:@"A"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_2A.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"B"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_2B.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"C"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_2C.pdf"]]]]; }
}
if ([[array1 objectAtIndex:row] isEqual:@"3"]) {
if ([[array2 objectAtIndex:row] isEqual:@"A"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_3A.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"B"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_3B.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"C"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_3C.pdf"]]]]; }
}
if ([[array1 objectAtIndex:row] isEqual:@"4"]) {
if ([[array2 objectAtIndex:row] isEqual:@"A"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_4A.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"B"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_4B.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"C"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_4C.pdf"]]]]; }
}
if ([[array1 objectAtIndex:row] isEqual:@"5"]) {
if ([[array2 objectAtIndex:row] isEqual:@"A"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_5A.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"B"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_5B.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"C"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_5C.pdf"]]]]; }
}
if ([[array1 objectAtIndex:row] isEqual:@"6"]) {
if ([[array2 objectAtIndex:row] isEqual:@"A"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_6A.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"B"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_6B.pdf"]]]]; }
if ([[array2 objectAtIndex:row] isEqual:@"C"]) {
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Stundenplan_6C.pdf"]]]]; }
}
На:
NSString *numberString = [array1 objectAtIndex:row];
NSString *letterString = [array2 objectAtIndex:row];
NSString *pathComponentString = [NSString stringWithFormat:@"Stundenplan_%@%@.pdf", numberString, letterString];
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pathComponentString]]]];
В первых двух строках (упрощенного кода) вы видите проблему:Если строка имеет значение 3 или больше, вы не можете вызвать [array2 objectAtIndex:row];
, длина которого составляет всего 3.
Редактировать
Вы можете использовать метод:
- (NSInteger)selectedRowInComponent:(NSInteger)component;
Чтобы определить правильные индексы букв и цифр:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *numberString = [array1 objectAtIndex:[pickerView selectedRowInComponent:0]];
NSString *letterString = [array2 objectAtIndex:[pickerView selectedRowInComponent:1]];
NSString *pathComponentString = [NSString stringWithFormat:@"Stundenplan_%@%@.pdf", numberString, letterString];
stundenplan.scalesPageToFit = YES;
[stundenplan loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pathComponentString]]]];
}