【问题标题】:Loading a document into a Webview将文档加载到 Webview
【发布时间】:2010-12-08 12:22:08
【问题描述】:

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

   -(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];
         }
     }

谁能帮帮我..

【问题讨论】:

    标签: iphone objective-c cocoa-touch uiwebview


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:
      - (void)webViewDidFinishLoad:(UIWebView *)webViewload { 
      

      只有在你设置了 webView 的委托时才会被调用(在 xib &.h 文件中)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-10
        • 2011-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多