Iphone 易延迟加载
我已经使用类Iphone 易延迟加载,iphone,objective-c,ios,uitableview,uiimageview,Iphone,Objective C,Ios,Uitableview,Uiimageview,我已经使用类UIImageView+WebCache.h成功地实现了延迟加载。 有没有什么简单的方法可以在不使用类UIImageView+WebCache.h的情况下进行延迟加载?您可以在UIWebView中加载图像。例如: -(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"ID"
UIImageView+WebCache.h
成功地实现了延迟加载。
有没有什么简单的方法可以在不使用类
UIImageView+WebCache.h的情况下进行延迟加载?您可以在UIWebView中加载图像。例如:
-(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"ID";
UITableViewCell *cell = [self.tv dequeueReusableCellWithIdentifier:identifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
NSLog(@"URL=%@",[arrayURL objectAtIndex:indexPath.row]);
NSURL *url=[NSURL URLWithString:[arrayURL objectAtIndex:indexPath.row]];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
[webView loadRequest:req];
webView.scalesPageToFit=TRUE;
[cell.contentView addSubview:webView];
}
return cell;
}
您可以在UIWebView中加载图像。例如:
-(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"ID";
UITableViewCell *cell = [self.tv dequeueReusableCellWithIdentifier:identifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
NSLog(@"URL=%@",[arrayURL objectAtIndex:indexPath.row]);
NSURL *url=[NSURL URLWithString:[arrayURL objectAtIndex:indexPath.row]];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
[webView loadRequest:req];
webView.scalesPageToFit=TRUE;
[cell.contentView addSubview:webView];
}
return cell;
}
我不想破坏你的回答,但我看到了两个潜在的问题:1。UIWebView仅添加到新分配的单元格,而不添加到重用的单元格。2. loadRequest
是异步工作的,因此当请求完成时,单元格可能已被重新用于其他行。我不想破坏您的答案,但我发现两个潜在问题:1。UIWebView仅添加到新分配的单元格,而不添加到重用的单元格。2. loadRequest
是异步工作的,因此当请求完成时,单元格可能已经被重新用于其他行。