Ios UITableViewCell中的UIWebview

Ios UITableViewCell中的UIWebview,ios,objective-c,uitableview,uiwebview,Ios,Objective C,Uitableview,Uiwebview,我有一个自定义单元格,其中包含一个web视图-问题是我只想调用请求来加载web视图的URL一次。现在我正在CellForRowatinex中加载请求:当然这会使请求被多次调用。如何确保请求只发出一次,以及执行此操作的最佳方式是什么?维护数据结构以存储来自web请求的响应将解决此问题。比如说,对于第一次在数据结构中查找的indepath(NSMutableArray更合适),当您第一次查找数据时,您将找不到任何响应,然后获取响应并将其存储到数据结构中。然后第二次,当单元格同时indepath在数据

我有一个自定义单元格,其中包含一个web视图-问题是我只想调用请求来加载web视图的URL一次。现在我正在CellForRowatinex中加载请求:当然这会使请求被多次调用。如何确保请求只发出一次,以及执行此操作的最佳方式是什么?

维护数据结构以存储来自web请求的响应将解决此问题。比如说,对于第一次在数据结构中查找的
indepath
NSMutableArray
更合适),当您第一次查找数据时,您将找不到任何响应,然后获取响应并将其存储到数据结构中。然后第二次,当单元格同时
indepath
在数据结构中查找时,瞧,这次您不必发出请求

为了简单起见,我使用了
NSMutableDictionary
named
responseData

  • viewDidLoad
  • cellForRowAtIndexPath

    UITableViewCell *cell = //deque the cell
    
    NSString *responseKey = [NSString stringWithFormat:"%d,%d", indexPath.section,indexPath.row];
    
    NSString *htmlData = responseData[responseKey];
    
    if(htmlData == nil)
    {
        htmlData = //whatever the way do your request, put the response in the htmlData. as you are doing asynchronous loading of the web-request, set the cell's webView in the completion. NB:: do gui related work on gui/main thread.
    
        responseData[responseKey] = htmlData;
    }
    
    //set the htmlData to your, cell's webView
    

  • 仅发出一次请求,或当用户可以看到单元格时发出请求?或者,您可以在单元格中首次使用rowat index方法后,使用bool标志并将其设置为NO。有关html内容和UIWebView的帮助信息,请查看