Programming
Determine file extension on tap and push view controlelr

Question Description

Basically I need to know how a webview knows what kind of file extension is being tapped, (png, zip, etc) and then push another view controller. So far I have this.

UPDATE 6/13 - I have updated my code per what Hunter has suggested, yet it still only opens the png, instead of pushing the vc.

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {        

       

        if(navigationType == UIWebViewNavigationTypeLinkClicked) {

            NSURL *theRessourcesURL = [request URL];

            NSString *fileExtension = [theRessourcesURL pathExtension];

            if ([fileExtension isEqualToString:@"png"]) {

               

                MYViewController *vc = [[MYViewController alloc] init];

                [dlvc downloadURL:theRessourcesURL userInfo:nil];

                [self.navigationController pushViewController:vc animated:YES];

               

                vc.delegate = self;

            }            

            else{}

        }      

        return YES;

    }

I have tried this before without the file extension code and it will push another view just fine.

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

        if(navigationType == UIWebViewNavigationTypeLinkClicked) {

            NSURL *theRessourcesURL = [request URL];

   

   

            DetailViewController *vc = [[DetailViewController alloc] init];

            [vc downloadURL:theRessourcesURL userInfo:nil];

            [self.navigationController pushViewController:vc animated:YES];

   

            vc.delegate = self;

   

        }

   

        return YES;

    }

I also tried to use this as a starter base without success, as I don't use interface builder, so I don't know if IBActions can be used (if they can I dont know how to implement them properly). http://stackoverflow.com/questions/7377565/how-to-download-files-from-uiwebview-and-open-again

Any help would be appreciated.


Final Answer

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIViewController *viewController1 = [[DemoFirstViewController alloc] initWithNibName:@"DemoFirstViewController" bundle:nil];
UIViewController *viewController2 = [[DemoSecondViewController alloc] initWithNibName:@"DemoSecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigationController;

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIViewController *viewController1 = [[DemoFirstViewController alloc] initWithNibName:@"DemoFirstViewController" bundle:nil];

// here I create a Navigation Controller and set its root view controller to viewController1
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];

UIViewController *viewController2 = [[DemoSecondViewController alloc] initWithNibName:@"DemoSecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];

// updated this line to show the navController1 (which contains viewController1)
self.tabBarController.viewControllers = @[navController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;

seeker (18)
UCLA

Anonymous
The tutor managed to follow the requirements for my assignment and helped me understand the concepts on it.

Anonymous
The tutor was knowledgeable, will be using the service again.

Anonymous
Awesome quality of the tutor. They were helpful and accommodating given my needs.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors