Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:14:23+00:00 2026-05-30T01:14:23+00:00

I tried to control my UIWebView with a UIPickerView, in order to display different

  • 0

I tried to control my UIWebView with a UIPickerView, in order to display different PDF files. But somehow my code doesn’t. Either it crashes if I select a certain row or it displays the wrong PDF. Any ideas?

#import "PickerViewTutorialViewController.h"

@implementation PickerViewTutorialViewController

@synthesize pickerView;

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self populateArray1];
    [self populateArray2];
}

- (void)populateArray1 {
    array1 = [[NSMutableArray alloc] init];
    [array1 addObject:@"1"];
    [array1 addObject:@"2"];
    [array1 addObject:@"3"];
    [array1 addObject:@"4"];
    [array1 addObject:@"5"];
    [array1 addObject:@"6"];
}
- (void)populateArray2 {
    array2 = [[NSMutableArray alloc] init];
    [array2 addObject:@"A"];
    [array2 addObject:@"B"];
    [array2 addObject:@"C"];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark picker view methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 2;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    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"]]]]; }
    }
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
    if (component == 0) {
        return [array1 count];
    }
    else {
        return [array2 count];
    }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
    if (component == 0) {
        return [array1 objectAtIndex:row];
    }
    else {
        return [array2 objectAtIndex:row];
    }
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:14:25+00:00Added an answer on May 30, 2026 at 1:14 am

    Note that you can replace all of the code:

        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"]]]]; }
        }
    

    By:

    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]]]];
    

    In the first two lines (of the simplified code), you see the problem: When row is 3 or greater, you can’t call [array2 objectAtIndex:row]; which has a length of only 3.

    Edit

    You can use the method:

    - (NSInteger)selectedRowInComponent:(NSInteger)component;
    

    To determine the correct indices of the letters and numbers:

    - (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]]]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to control email address and reviewer's name with the following code but
I've tried using source control for a couple projects but still don't really understand
I tried to make a custom pushpin for the Bing Maps silverlight control, but
When I tried To Find Control n data List As I Mentioned Below Error(Object
Have you tried to use SharePoint with version control such as Perforce (or Subversion),
I was using Codeplex and tried connecting to their source control using Team Explorer,
I created an ActiveX control ocx file using Visual Studio 2008. Then tried registering
I have tried to understand AOP, Dependency Injection and Inversion of Control SPRING related
I want to double buffer a custom control which contains buttons. I have tried
how can I remove the space between my video and control bar... I tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.