导航时停止webview加载

时间:2013-09-23 01:25:50

标签: ios image webview

基本上我有一个webview,当点击某些文件扩展名时会打开一个新的视图控制器来查看图像。在iOS 6中,[webView stopLoading]完美地阻止了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];

1 个答案:

答案 0 :(得分: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];