2013-09-23 93 views
0

基本上我有一個web瀏覽器,當點擊某些文件擴展名時會打開一個新的視圖控制器來查看圖像。在iOS 6中,[webView stopLoading]在停止webview以通過視圖控制器方面完美地工作。在導航時停止webview加載

由於升級到iOS 7,這隻會工作一次或兩次,但然後它會打開webview中的圖像,並通過視圖控制器。

下面是我與以前的工作在IOS 6

任何幫助,將不勝感激。

/////////////// 
//IMAGE CODE/// 
/////////////// 
       //Image file links 
       NSURL *imageURl = [request URL]; 
       NSString *imageFileExtension = [[imageURl absoluteString] pathExtension]; 

       //Image file extensions 
       NSLog(@"fileExtension is: %@", imageFileExtension); 
       if ([imageFileExtension hasSuffix:@"png"] || [imageFileExtension hasSuffix:@"jpg"] || [imageFileExtension hasSuffix:@"jpeg"] || [imageFileExtension hasSuffix:@"gif"] || [imageFileExtension hasSuffix:@"bmp"] || [imageFileExtension hasSuffix:@"raw"] || [imageFileExtension hasSuffix:@"PNG"] || [imageFileExtension hasSuffix:@"JPG"] || [imageFileExtension hasSuffix:@"JPEG"] || [imageFileExtension hasSuffix:@"GIF"] || [imageFileExtension hasSuffix:@"BMP"] || [imageFileExtension hasSuffix:@"RAW"]) { 

        [webView stopLoading]; 
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

        //Image manager 
        WebImageViewController * vc = [[WebImageViewController alloc] initWithURL:[request URL]]; 
        [self.navigationController pushViewController:vc animated:YES]; 
        [vc release]; 

       }else{ 

        //Image file links 
        NSURL *imageURl = [request URL]; 
        NSString *imageFileExtension = [imageURl pathExtension]; 

        //Image file extensions 
        NSLog(@"fileExtension is: %@", imageFileExtension); 
       if ([imageFileExtension hasSuffix:@"png"] || [imageFileExtension hasSuffix:@"jpg"] || [imageFileExtension hasSuffix:@"jpeg"] || [imageFileExtension hasSuffix:@"gif"] || [imageFileExtension hasSuffix:@"bmp"] || [imageFileExtension hasSuffix:@"raw"] || [imageFileExtension hasSuffix:@"PNG"] || [imageFileExtension hasSuffix:@"JPG"] || [imageFileExtension hasSuffix:@"JPEG"] || [imageFileExtension hasSuffix:@"GIF"] || [imageFileExtension hasSuffix:@"BMP"] || [imageFileExtension hasSuffix:@"RAW"]) {       

        [webView stopLoading]; 
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

        //Image manager 
        WebImageViewController * vc = [[WebImageViewController alloc] initWithURL:[request URL]]; 
        [self.navigationController pushViewController:vc animated:YES]; 
        [vc release]; 

        }else{ 

        //Image file links 
        NSURL *imageURl = [request URL]; 
        NSString *imageFileExtension = [imageURl absoluteString]; 

        //Image file extensions 
        NSLog(@"fileExtension is: %@", imageFileExtension); 
       if ([imageFileExtension hasSuffix:@"png"] || [imageFileExtension hasSuffix:@"jpg"] || [imageFileExtension hasSuffix:@"jpeg"] || [imageFileExtension hasSuffix:@"gif"] || [imageFileExtension hasSuffix:@"bmp"] || [imageFileExtension hasSuffix:@"raw"] || [imageFileExtension hasSuffix:@"PNG"] || [imageFileExtension hasSuffix:@"JPG"] || [imageFileExtension hasSuffix:@"JPEG"] || [imageFileExtension hasSuffix:@"GIF"] || [imageFileExtension hasSuffix:@"BMP"] || [imageFileExtension hasSuffix:@"RAW"]) {        

        [webView stopLoading]; 
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

        //Image manager 
        WebImageViewController * vc = [[WebImageViewController alloc] initWithURL:[request URL]]; 
        [self.navigationController pushViewController:vc animated:YES]; 
        [vc release]; 

回答

0

所以我覺得我設法讓這個工作。隨着一些重新編碼和調整我想出了這個:

 NSURL *imageURl = [request URL]; 
     NSString *imageFileExtension = [[imageURl absoluteString] pathExtension]; 

     NSSet *supportedFileExtensions = [NSSet setWithObjects:@"png", @"jpg", @"jpeg", @"gif", @"bmp", @"pdf", @"raw", nil]; 

     if ([supportedFileExtensions containsObject:[imageFileExtension lowercaseString]]) { 

      [webView stopLoading]; 

      //Image manager 
      [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

      WebImageViewController * vc = [[WebImageViewController alloc] initWithURL:[request URL]]; 
      [self.navigationController pushViewController:vc animated:YES]; 
      [vc release];