将文档加载到Webview中

时间:2010-12-08 12:22:08

标签: iphone objective-c cocoa-touch uiwebview

我试图将.docx文件加载到uiwebview中并显示它。要将文档加载到webview中,它需要几分钟的时间,所以我可以在内容出现在屏幕上之前看到一个白色的空白屏幕.I不想在加载时看到白色屏幕而不是我想做一些动作如活动指示器或改变背景。我怎么能实现这一点请帮助我。 这是我的代码;

   -(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews
       {
  webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
isWebviewLoaded=YES;
    webView.delegate=self;
    webView.alpha=0;

 NSString *path = [[NSBundle mainBundle] pathForResource:@"SKIN   ADVISORuser_updated.docx" ofType:nil];
    //NSString *path = [[NSBundle mainBundle]pathForResource:@"UserGuidelines3.html" ofType:nil];
     NSURL *url = [NSURL fileURLWithPath:path];
   NSURLRequest *request = [NSURLRequest requestWithURL:url];

      [webViews loadRequest:request];
}

并在viewdidload中调用上面的方法:

[self loadDocument:@"ADVISORuser_updated.docx" inView:self.webView];

即使是实现委托方法来更改背景但是委托没有执行

      - (void)webViewDidFinishLoad:(UIWebView *)webViewload {
     if (isWebviewLoaded) 
     {
    isWebviewLoaded = NO;
     webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage     imageNamed:@"Instructions Screen Background light_PNG.png"]];
    [UIView beginAnimations:@"webView" context:nil];
       webView.alpha = 1.0;
       [UIView commitAnimations];
         }
     }

请任何人帮助我..

2 个答案:

答案 0 :(得分:0)

- (void)webViewDidFinishLoad:(UIWebView *)webViewload { 
只有在为webView设置委托时才会调用

(在xib& .h文件中)

答案 1 :(得分:0)

在loadRequest之前,你可以创建UIActivityIndi​​cator对象并通过调用start方法启动它

在webView委托中didFinishLoading:& didFailwithError方法暂停活动指示器