zoukankan      html  css  js  c++  java
  • iphone table 实现动态加载图片

    Iphone在加载列表时,如果每个等待把所有列表中的数据都加载完在显示相关内容,如果列表中有一些比较大的图片,加载的时间比较长,那么给用户的效果就很差了,下面详细是一种实现动态加载图片的办法:

        -(UITableViewCell*)tableView:(UITableView*)tableView
                 cellForRowAtIndexPath
    :(NSIndexPath*)indexPath {
           
    UITableViewCell* cell =[tableView dequeueReusableCellWithIdentifier:@"tag"];
           
    if(cell==nil){
                cell
    =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                               reuseIdentifier
    :@"tag"] autorelease];
           
    }  
           
    //表格设计
           
    NSDictionary* one =[array objectAtIndex:indexPath.row];
            cell
    .textLabel.text =[one objectForKey:@"title"];
            cell
    .detailTextLabel.text =[one objectForKey:@"content"];
             
    [NSThread detachNewThreadSelector:@selector(updateImageForCellAtIndexPath:) toTarget:self withObject:indexPath];
           
    return cell;
       
    }

       
    -(void)updateImageForCellAtIndexPath:(NSIndexPath*)indexPath
       
    {
           
    NSAutoreleasePool*pool =[[NSAutoreleasePool alloc] init];
           
    UIImage*image =[self getImageForCellAtIndexPath:indexPath];
           
    UITableViewCell*cell =[self.tableView cellForRowAtIndexPath:indexPath];
           
    [cell.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];
           
    [image release];
           
    [pool release];
       
    }
       
    -(UIImage*)getImageForCellAtIndexPath:(NSIndexPath*)indexPath
       
    {
            id path
    =[[array objectAtIndex:indexPath.row] objectForKey:@"image"];
            NSURL
    *url =[NSURL URLWithString:path];
           
    NSData*data =[NSData dataWithContentsOfURL:url];
           
    UIImage*image =[[UIImage alloc] initWithData:data cache:NO];
           
    return image;
       
    }
    风之境地 java-javascript 蘑菇街女装
  • 相关阅读:
    创建文件并写入内容
    java自动压缩文件并加密
    Java自动发送带图片邮件(带附件)
    eclipse正则表达式搜索
    解决:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
    spring整合mybatis(原始dao和mapper代理两种方式)
    (解决)mysql1366中文显示错误的终极解决方案
    pdf合并、拆分工具
    ScheduledExecutorService定时方法
    json数据包含特殊字符解析失败
  • 原文地址:https://www.cnblogs.com/sky7034/p/1992416.html
Copyright © 2011-2022 走看看