• <tfoot id='A4VVR'></tfoot>

    <small id='A4VVR'></small><noframes id='A4VVR'>

  • <legend id='A4VVR'><style id='A4VVR'><dir id='A4VVR'><q id='A4VVR'></q></dir></style></legend>
      • <bdo id='A4VVR'></bdo><ul id='A4VVR'></ul>

        <i id='A4VVR'><tr id='A4VVR'><dt id='A4VVR'><q id='A4VVR'><span id='A4VVR'><b id='A4VVR'><form id='A4VVR'><ins id='A4VVR'></ins><ul id='A4VVR'></ul><sub id='A4VVR'></sub></form><legend id='A4VVR'></legend><bdo id='A4VVR'><pre id='A4VVR'><center id='A4VVR'></center></pre></bdo></b><th id='A4VVR'></th></span></q></dt></tr></i><div id='A4VVR'><tfoot id='A4VVR'></tfoot><dl id='A4VVR'><fieldset id='A4VVR'></fieldset></dl></div>
      1. 将 NSData 加载到 UIWebView

        Loading NSData into a UIWebView(将 NSData 加载到 UIWebView)
            • <tfoot id='z1aps'></tfoot>

              1. <legend id='z1aps'><style id='z1aps'><dir id='z1aps'><q id='z1aps'></q></dir></style></legend>
                <i id='z1aps'><tr id='z1aps'><dt id='z1aps'><q id='z1aps'><span id='z1aps'><b id='z1aps'><form id='z1aps'><ins id='z1aps'></ins><ul id='z1aps'></ul><sub id='z1aps'></sub></form><legend id='z1aps'></legend><bdo id='z1aps'><pre id='z1aps'><center id='z1aps'></center></pre></bdo></b><th id='z1aps'></th></span></q></dt></tr></i><div id='z1aps'><tfoot id='z1aps'></tfoot><dl id='z1aps'><fieldset id='z1aps'></fieldset></dl></div>

                  <tbody id='z1aps'></tbody>

                <small id='z1aps'></small><noframes id='z1aps'>

                  <bdo id='z1aps'></bdo><ul id='z1aps'></ul>
                • 本文介绍了将 NSData 加载到 UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的网络浏览器中,我尝试使用从 NSURLConnection 获得的 NSData 加载 UIWebView.当我尝试将其加载到 UIWebView 中时,它会显示 HTML 纯文本,而不是站点.

                  In my web browser, I am trying to load a UIWebView with NSData obtained from a NSURLConnection. When I try to load it into the UIWebView, instead of the site, it comes up with the HTML plain text.

                  这是我的代码:

                  viewDidLoad:

                  NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.msn.com"]];
                  [NSURLConnection connectionWithRequest: request delegate:self];
                  

                  后面的代码:

                   -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
                    {
                       webdata = [NSMutableData dataWithData: data];
                    }
                  
                   -(void)connectionDidFinishLoading:(NSURLConnection *)connection
                    {
                      [webview loadData:webdata MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil];
                    }
                  

                  推荐答案

                  您没有附加您正在接收的数据.使用这段代码

                  You are not appending data that you are receiving. Use this piece of code

                  -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
                      if (webdata == nil) {
                          webdata = [[NSMutableData alloc] init];
                      }
                      [webdata appendData:data];
                  }
                  

                  此方法可能会被调用一次或多次,具体取决于您的数据长度.因此,不要将新数据分配给您的 ivar,而是将您的数据附加到它,以便您获得完整的响应,而不是收到的最后一个数据包.
                  -----------------------------------------------------------------------------------------------------------------------------------
                  更新
                  或者像这样使用.

                  This method might be called once or more times depending upon your data length. So instead of assigning new data to your ivar, append your data to it so that you have the full response not the last packet of data received.
                  ------------------------------------------------------------------------------------------------------------------------------------
                  Updated
                  Or use like this.

                  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
                          webdata = [[NSMutableData alloc] init];
                  }
                  -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
                      [webdata appendData:data];
                  }
                  
                  -(void)connectionDidFinishLoading:(NSURLConnection *)connection{
                      [mWebView loadData:webdata MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil];
                  }
                  

                  这篇关于将 NSData 加载到 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)

                • <legend id='4maZR'><style id='4maZR'><dir id='4maZR'><q id='4maZR'></q></dir></style></legend>
                  <tfoot id='4maZR'></tfoot>

                  <small id='4maZR'></small><noframes id='4maZR'>

                  <i id='4maZR'><tr id='4maZR'><dt id='4maZR'><q id='4maZR'><span id='4maZR'><b id='4maZR'><form id='4maZR'><ins id='4maZR'></ins><ul id='4maZR'></ul><sub id='4maZR'></sub></form><legend id='4maZR'></legend><bdo id='4maZR'><pre id='4maZR'><center id='4maZR'></center></pre></bdo></b><th id='4maZR'></th></span></q></dt></tr></i><div id='4maZR'><tfoot id='4maZR'></tfoot><dl id='4maZR'><fieldset id='4maZR'></fieldset></dl></div>
                  • <bdo id='4maZR'></bdo><ul id='4maZR'></ul>
                        <tbody id='4maZR'></tbody>