0

我在 UIViewController 中有一个 UIWebView。我正在通过此功能为 UIWebView 加载内容:

 - (void)loadHTMLString:(NSString *)html {
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [self.webView loadHTMLString:html baseURL:baseURL];
}

如果我的内容包含许多图像,我会通过 FGallery ( https://github.com/gdavis/FGallery-iPhone ) 创建一个画廊。当我第一次打开 UIViewController 时,我正在 UIWebView 中加载图像和文本。我关闭应用程序并关闭网络。然后我打开我的应用程序并打开一个 UIViewController。我正在从缓存中加载我的 UIWebView。但我有一个问题。如果我在关闭网络之前打开图库,则不会从缓存中加载图库的封面,但会加载图库中的所有图像。如果我在关闭网络之前没有打开画廊,画廊的封面将从缓存中加载。画廊的封面和画廊的第一张图片是一样的。

如果我打开一个画廊,为什么画廊的封面不加载?

4

1 回答 1

1

可能是webview的合适答案

- (BOOL)webView:(UIWebView*)webViewRef shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeLinkClicked) 
    {
        NSURL *URL = [request URL]; //Get the URL
        if ( [[URL scheme] isEqualToString:@"objc"] ) {
            webView = webViewRef;
            SEL method = NSSelectorFromString( [URL host] );
            if ([self respondsToSelector:method])
            {
                [self performSelector:method withObject:nil afterDelay:0.1f];
            }
            return NO;
        }
    }
   return YES;
}
-(void)takePicture
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;
    id delegate = [[UIApplication sharedApplication] delegate];
    [[delegate viewController] presentModalViewController:imagePicker animated:YES];
    [imagePicker release];
}

#pragma mark - Image Picker

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    NSData *flatImage = UIImageJPEGRepresentation(image, 0.1f);
    NSString *image64 = [flatImage base64EncodedString];
    NSString *js = [NSString stringWithFormat: @"processImage('data:image/jpeg;base64,%@')", image64];
    [webView stringByEvaluatingJavaScriptFromString:js];
    [picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    //cancel was hit inside of the camera view
    [picker dismissModalViewControllerAnimated:YES];
}
于 2013-07-01T11:00:19.093 回答