IOS 延时加载TableView中Cell中的图片

原创
2013/02/22 17:41
阅读数 1.3K
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // do something
    [NSThread detachNewThreadSelector:@selector(startImageread:) toTarget:self withObject:indexPath]; // 获取图片
    // do something
}

-(void)startImageread:(NSIndexPath *)indexPath
{                                                                                                      UIImage *newimage = ......// 从本地或者网络获取图片
    NSDictionary *cellimage = [NSDictionary dictionaryWithObjectsAndKeys:
                               indexPath, @"indexPath",
                               newimage,@"image",
                               nil];
    [self performSelectorOnMainThread:@selector(_setOCellImage:) withObject:cellimage waitUntilDone:YES];
}

- (void)_setOCellImage:( id )celldata
{
    UIImage *newimage = [celldata objectForKey:@"image"];//从参数celldata里面拿出来图片
    NSIndexPath *indexPath = [celldata objectForKey:@"indexPath"];
    [self.DataTable cellForRowAtIndexPath:indexPath].imageView.image = newimage;
}
展开阅读全文
加载中

作者的其它热门文章

打赏
0
3 收藏
分享
打赏
0 评论
3 收藏
0
分享
返回顶部
顶部
返回顶部
顶部