我有tableview名称“tableAll”,数组“thumbVideoListArray”(首先这个数组为空)并且有数组“objDelegate.listVidArray”,其中包含图像的url ..认为我有错误检查。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([thumbVideoListArray count] == 0)
{
[NSThread detachNewThreadSelector:@selector(fetchImage:) toTarget:self withObject:indexPath];
}
else
{
UIImage *img1 = [thumbVideoListArray objectAtIndex:indexPath.row];
if(img1)
{
cell.thumbImage = [thumbVideoListArray objectAtIndex:indexPath.row];
}
else
{
[NSThread detachNewThreadSelector:@selector(fetchImage:) toTarget:self withObject:indexPath];
}
}
}
- (void)fetchImage:(NSIndexPath *)indexPath
{
NSLog(@"in thead");
if([[[[objDelegate.listVidArray objectAtIndex:[objDelegate.listVidArray count]-(indexPath.section+1)]valueForKey:@"videoList"]valueForKey:@"media_id"]objectAtIndex:indexPath.row])
{
NSData *dataImage = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[[[objDelegate.listVidArray objectAtIndex:[objDelegate.listVidArray count]-(indexPath.section+1)]valueForKey:@"videoList"]valueForKey:@"img"]objectAtIndex:indexPath.row]]]];
if([dataImage length])
{
UIImage *imageThumb = [UIImage imageWithData:dataImage];
[thumbVideoListArray addObject:imageThumb];
// Reload rows with the fetched image in other thread
[self performSelectorOnMainThread:@selector(reloadTable:) withObject:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] waitUntilDone:NO];
}
}
}
- (void)reloadTable:(NSArray *)array
{
[tableAll reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
}
答案 0 :(得分:0)
In -tableView:cellForRowAtIndexPath:你永远不会抓住你的单元格对象。您需要在设置其属性之前使可重用单元出列。您还需要返回单元格。
答案 1 :(得分:0)
我认为您可以尝试AsyncImageView从网络
延迟加载图片答案 2 :(得分:0)
您需要进行一些修改,因为这不是一个好方法,而不是它,您可以做什么,您只需根据您的要求在viewDidLoad或viewWillAppear调用您的获取过程,然后重新加载您的表...更重要的是,不要忘记在这里使用NSOperation并标记你加载的数据,以便它可以调整你的单元格...希望,它会解决你的问题...因为我做了很多次。